{"record":{"id":"9a74ea33165f1412","repo":"vercel/next.js","slug":"failed-to-uninstall-packagetouninstall-pleas","errorCode":null,"errorMessage":"Failed to uninstall \"${packageToUninstall}\". Please uninstall it manually.","messagePattern":"Failed to uninstall \"(.+?)\"\\. Please uninstall it manually\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next-codemod/lib/handle-package.ts","lineNumber":119,"sourceCode":"export function uninstallPackage(\n  packageToUninstall: string,\n  pkgManager?: PackageManager\n) {\n  pkgManager ??= getPkgManager(process.cwd())\n  if (!pkgManager) throw new Error('Failed to find package manager')\n\n  let command = 'uninstall'\n  if (pkgManager === 'yarn') {\n    command = 'remove'\n  }\n\n  try {\n    execa.sync(pkgManager, [command, packageToUninstall], {\n      stdio: 'inherit',\n      shell: true,\n    })\n  } catch (error) {\n    throw new Error(\n      `Failed to uninstall \"${packageToUninstall}\". Please uninstall it manually.`,\n      { cause: error }\n    )\n  }\n}\n\nconst ADD_CMD_FLAG = {\n  npm: 'install',\n  yarn: 'add',\n  pnpm: 'add',\n  bun: 'add',\n}\n\nconst DEV_DEP_FLAG = {\n  npm: '--save-dev',\n  yarn: '--dev',\n  pnpm: '--save-dev',\n  bun: '--dev',","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next-codemod/lib/handle-package.ts#L101-L137","documentation":"Thrown by the `uninstallPackage` function in next-codemod when the underlying package manager subprocess (npm/pnpm/yarn/bun) exits with a non-zero status. The codemod runs `<pkgManager> <uninstall|remove> <package>` via execa.sync and catches the failure, re-throwing with a user-friendly message that asks you to finish the uninstall manually.","triggerScenarios":"Any next-codemod migration that calls `uninstallPackage` (e.g., removing a deprecated package during an upgrade codemod) and the spawned package manager command fails. The original subprocess error is attached as `cause`.","commonSituations":"The target package is already not installed; network or registry errors (timeout, 5xx); file permission errors (EACCES on node_modules); corrupted or locked node_modules; conflicting package manager lock files (e.g., both package-lock.json and pnpm-lock.yaml); running the codemod offline.","solutions":["Run the uninstall command manually to see the real error: `npm uninstall <package>` (or `pnpm remove`, `yarn remove`, `bun remove`).","Ensure only one package manager lock file exists (delete stale lock files and node_modules, then reinstall).","Check that the package manager binary is installed and on your PATH (`<pkgManager> --version`).","Retry the codemod after resolving the underlying package manager error."],"exampleFix":"// The codemod calls this internally:\nuninstallPackage('eslint-config-next')\n\n// If it fails, run the equivalent manually:\n// pnpm remove eslint-config-next","handlingStrategy":"try-catch","validationCode":"// Before calling uninstallPackage, verify the package is installed\nimport { readFileSync } from 'fs'\nfunction isPackageInstalled(name: string, cwd = process.cwd()): boolean {\n  try {\n    const pkg = JSON.parse(readFileSync(`${cwd}/package.json`, 'utf8'))\n    return Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name])\n  } catch { return false }\n}","typeGuard":null,"tryCatchPattern":"try {\n  uninstallPackage(packageToUninstall)\n} catch (e) {\n  // The cause holds the original execa error with stderr\n  console.error('Manual uninstall needed:', e.message)\n  if (e.cause) console.error('Underlying error:', e.cause.shortMessage ?? e.cause)\n}","preventionTips":["Ensure the package manager binary is on PATH and functional before running codemods.","Keep only one lock file in the project to avoid package manager confusion.","Run codemods with network access available, or pre-install the affected packages."],"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"}