You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用@next/codemod升级Next.js14到15时遭遇ERR_INVALID_ARG_TYPE错误

解决Next.js Codemod升级时的"Failed to install dependencies"错误(ERR_INVALID_ARG_TYPE)

问题场景

执行命令npx @next/codemod@canary upgrade latest将Next.js 14.2.13项目升级到15版本,在选择要应用的codemods及React19升级选项后,触发以下错误:

Error: Failed to install dependencies
    at runInstallation (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/lib/handle-package.js:98:15)
    at runUpgrade (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/bin/upgrade.js:260:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.<anonymous> (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/bin/next-codemod.js:51:9) {
  [cause]: TypeError [ERR_INVALID_ARG_TYPE]: Command failed with ERR_INVALID_ARG_TYPE:  install
  The "file" argument must be of type string. Received undefined
      at normalizeSpawnArguments (node:child_process:548:3)
      at Object.spawnSync (node:child_process:836:8)
      at module.exports.sync (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/execa/index.js:169:25)
      at runInstallation (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/lib/handle-package.js:91:25)
      at runUpgrade (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/bin/upgrade.js:260:42)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Command.<anonymous> (/home/esteban/.npm/_npx/6a090669e21b4303/node_modules/@next/codemod/bin/next-codemod.js:51:9) {
    code: 'ERR_INVALID_ARG_TYPE',
    originalMessage: 'The "file" argument must be of type string. Received undefined',
    shortMessage: 'Command failed with ERR_INVALID_ARG_TYPE:  install\n' +
      'The "file" argument must be of type string. Received undefined',
    command: ' install',
    exitCode: undefined,
    signal: undefined,
    signalDescription: undefined,
    stdout: '',
    stderr: '',
    all: '',
    failed: true,
    timedOut: false,
    isCanceled: false,
    killed: false
  }
}

已尝试的无效操作

  • 接受或拒绝React19更新均无法解决问题
  • 清理npm缓存并重新安装依赖后问题依旧
  • 手动升级Next.js并单独应用各个codemods可正常完成

环境信息

  • Node.js 20.17.0
  • npm 10.9.1
  • 操作系统:Fedora OS

解决方案

该错误源于codemod工具在处理依赖安装时无法正确识别包管理器执行路径,确保项目根目录存在package-lock.json文件即可修复:

  1. 如果项目目前没有package-lock.json,执行npm install生成该文件
  2. 重新运行npx @next/codemod@canary upgrade latest命令,即可完成自动升级流程

内容的提问来源于stack exchange,提问作者ereynier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 20:23:14