{"record":{"id":"649e52c786a50264","repo":"vercel/next.js","slug":"failed-to-install-dependencies","errorCode":null,"errorMessage":"Failed to install dependencies","messagePattern":"Failed to install dependencies","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next-codemod/lib/handle-package.ts","lineNumber":197,"sourceCode":"export function runInstallation(\n  packageManager: PackageManager,\n  options: { cwd: string }\n) {\n  try {\n    execa.sync(packageManager, ['install'], {\n      cwd: options.cwd,\n      env: {\n        ...process.env,\n        // In case NODE_ENV=production is set, we still want dev dependencies to\n        // be installed. Otherwise we won't be able to check for peer dependencies.\n        // --production=false is not implemented by every package manager.\n        NODE_ENV: 'development',\n      },\n      stdio: 'inherit',\n      shell: true,\n    })\n  } catch (error) {\n    throw new Error('Failed to install dependencies', { cause: error })\n  }\n}\n\nexport function addPackageDependency(\n  packageJson: Record<string, any>,\n  name: string,\n  version: string,\n  dev: boolean\n): void {\n  if (dev) {\n    packageJson.devDependencies = packageJson.devDependencies || {}\n  } else {\n    packageJson.dependencies = packageJson.dependencies || {}\n  }\n\n  const deps = dev ? packageJson.devDependencies : packageJson.dependencies\n\n  deps[name] = version","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next-codemod/lib/handle-package.ts#L179-L215","documentation":"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`.","triggerScenarios":"A codemod that needs to install the full dependency tree (e.g., after modifying package.json) calls `runInstallation` and the bare `install` command fails.","commonSituations":"Broken or inconsistent lock file; unresolvable dependency tree after package.json edits; registry or network failures; permission issues on node_modules; disk full.","solutions":["Run `<pkgManager> install` manually in the project root to see the real error.","Delete node_modules and the lock file, then run a fresh install.","Check for peer dependency resolution failures in the output.","Ensure you have sufficient disk space and write permissions."],"exampleFix":"// The codemod calls this internally:\nrunInstallation('pnpm', { cwd: projectRoot })\n\n// Run manually to diagnose:\n// cd <projectRoot> && pnpm install","handlingStrategy":"try-catch","validationCode":"// Verify the dependency tree is consistent before running install\nimport { existsSync } from 'fs'\nfunction preflightInstall(cwd: string): boolean {\n  return existsSync(`${cwd}/package.json`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  runInstallation('pnpm', { cwd: projectRoot })\n} catch (e) {\n  console.error('Install failed:', e.message)\n  if (e.cause) console.error('Cause:', e.cause.message)\n  throw e\n}","preventionTips":["Commit a clean, consistent lock file so `install` reproduces reliably.","Remove stale node_modules before running codemods that modify dependencies.","Watch for peer dependency warnings — resolve them before they become hard errors."],"tags":["codemod","package-manager","dependency-management","subprocess"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}