vercel/next.js · error

Failed to install dependencies

Error message

Failed to install dependencies

What it means

Thrown by `runInstallation` in next-codemod when `execa.sync` running `<pkgManager> install` (a bare install of all dependencies) exits non-zero. It sets NODE_ENV=development to ensure dev dependencies are included. The subprocess error is wrapped as `cause`.

Source

Thrown at packages/next-codemod/lib/handle-package.ts:197

export function runInstallation(
  packageManager: PackageManager,
  options: { cwd: string }
) {
  try {
    execa.sync(packageManager, ['install'], {
      cwd: options.cwd,
      env: {
        ...process.env,
        // In case NODE_ENV=production is set, we still want dev dependencies to
        // be installed. Otherwise we won't be able to check for peer dependencies.
        // --production=false is not implemented by every package manager.
        NODE_ENV: 'development',
      },
      stdio: 'inherit',
      shell: true,
    })
  } catch (error) {
    throw new Error('Failed to install dependencies', { cause: error })
  }
}

export function addPackageDependency(
  packageJson: Record<string, any>,
  name: string,
  version: string,
  dev: boolean
): void {
  if (dev) {
    packageJson.devDependencies = packageJson.devDependencies || {}
  } else {
    packageJson.dependencies = packageJson.dependencies || {}
  }

  const deps = dev ? packageJson.devDependencies : packageJson.dependencies

  deps[name] = version

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Run `<pkgManager> install` manually in the project root to see the real error.
  2. Delete node_modules and the lock file, then run a fresh install.
  3. Check for peer dependency resolution failures in the output.
  4. Ensure you have sufficient disk space and write permissions.

Example fix

// The codemod calls this internally:
runInstallation('pnpm', { cwd: projectRoot })

// Run manually to diagnose:
// cd <projectRoot> && pnpm install
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the dependency tree is consistent before running install
import { existsSync } from 'fs'
function preflightInstall(cwd: string): boolean {
  return existsSync(`${cwd}/package.json`)
}

Try / catch

try {
  runInstallation('pnpm', { cwd: projectRoot })
} catch (e) {
  console.error('Install failed:', e.message)
  if (e.cause) console.error('Cause:', e.cause.message)
  throw e
}

Prevention

When it happens

Trigger: A codemod that needs to install the full dependency tree (e.g., after modifying package.json) calls `runInstallation` and the bare `install` command fails.

Common situations: Broken or inconsistent lock file; unresolvable dependency tree after package.json edits; registry or network failures; permission issues on node_modules; disk full.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/649e52c786a50264. Report an issue: GitHub.