From 2f08db3c01f10adca309b5f9434687cc6ddc5519 Mon Sep 17 00:00:00 2001 From: Jonas Hanisch Date: Sat, 13 Dec 2025 21:34:13 +0100 Subject: [PATCH] fix: add npm fallback when bun install fails with alias packages (#265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add npm fallback when bun install fails with alias packages Bun has issues resolving npm alias packages (e.g., string-width-cjs, strip-ansi-cjs, wrap-ansi-cjs) that are defined in package-lock.json. When bun fails with 404 errors for these packages, we now fall back to npm which handles aliases correctly. This fixes the installation failure that many users are experiencing where bun install fails with: error: GET https://registry.npmjs.org/string-width-cjs/-/string-width-cjs-4.2.3.tgz - 404 The fallback is transparent to users - they will see a warning message and the installation will continue with npm. Fixes #262 Related: #261, #253 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude * fix: preserve original code style (single quotes) --------- Co-authored-by: Jonas Hanisch Co-authored-by: Claude --- plugin/scripts/smart-install.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/plugin/scripts/smart-install.js b/plugin/scripts/smart-install.js index 1a04fd24..12a49a3d 100644 --- a/plugin/scripts/smart-install.js +++ b/plugin/scripts/smart-install.js @@ -268,7 +268,11 @@ function needsInstall() { } /** - * Install dependencies using Bun + * Install dependencies using Bun with npm fallback + * + * Bun has issues with npm alias packages (e.g., string-width-cjs, strip-ansi-cjs) + * that are defined in package-lock.json. When bun fails with 404 errors for these + * packages, we fall back to npm which handles aliases correctly. */ function installDeps() { const bunPath = getBunPath(); @@ -281,11 +285,29 @@ function installDeps() { // Quote path for Windows paths with spaces const bunCmd = IS_WINDOWS && bunPath.includes(' ') ? `"${bunPath}"` : bunPath; + let bunSucceeded = false; try { execSync(`${bunCmd} install`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS }); + bunSucceeded = true; } catch { - // Retry with force flag - execSync(`${bunCmd} install --force`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS }); + // First attempt failed, try with force flag + try { + execSync(`${bunCmd} install --force`, { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS }); + bunSucceeded = true; + } catch { + // Bun failed completely, will try npm fallback + } + } + + // Fallback to npm if bun failed (handles npm alias packages correctly) + if (!bunSucceeded) { + console.error('⚠️ Bun install failed, falling back to npm...'); + console.error(' (This can happen with npm alias packages like *-cjs)'); + try { + execSync('npm install', { cwd: ROOT, stdio: 'inherit', shell: IS_WINDOWS }); + } catch (npmError) { + throw new Error('Both bun and npm install failed: ' + npmError.message); + } } // Write version marker