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

Vercel部署Next.js项目报错:无法检测Next.js版本

Vercel部署Next.js时「无法检测Next.js版本」问题排查与解决

问题核心

你遇到的问题是Vercel构建时抛出Error: No Next.js version could be detected in your project,尽管package.json里已明确声明next依赖,但依赖安装仅耗时0.05秒(明显异常,正常依赖安装不会这么快)。

问题根源

查看你提供的package.json,存在JSON语法错误:文件内重复定义了scripts字段。JSON规范不允许同一对象内出现重复键,解析时后面的scripts会直接覆盖前面的,同时Yarn在解析存在语法错误的package.json时,会跳过实际的依赖安装流程,导致项目中根本没有安装任何依赖,自然检测不到Next.js。

修复步骤

1. 合并重复的scripts字段

将两个scripts中的命令合并为一个字段,保留所有必要的构建、启动命令:

{
  "name": "portfolio_site",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "node_modules/next/dist/bin/next start -p $PORT"
  },
  "dependencies": {
    "@next/font": "13.1.1",
    "autoprefixer": "^10.4.13",
    "date-fns": "^2.29.3",
    "dotenv": "^16.0.3",
    "eslint": "8.31.0",
    "eslint-config-next": "13.1.1",
    "next": "^13.1.1",
    "next-themes": "^0.2.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-lottie-player": "^1.5.4"
  },
  "devDependencies": {
    "tailwindcss": "^3.2.4"
  },
  "engines": {
       "node": "16.X"
  }
}

2. 额外排查项

  • 提交修复后的package.json到GitHub仓库,重新触发Vercel构建。
  • 如果问题仍存在,可在Vercel项目设置中指定包管理器为npm(避免Yarn解析异常),或添加vercel-build脚本明确构建步骤:
    "scripts": {
      // ...其他命令
      "vercel-build": "npm install && next build"
    }
    

附原始错误信息与代码

构建序列日志

[23:41:09.846] Running build in Cleveland, USA (East) – cle1
[23:41:09.895] Cloning github.com/minsing-jin/web_study_2 (Branch: main, Commit: 15e242e)
[23:41:10.150] Previous build cache not available
[23:41:10.214] Cloning completed: 318.763ms
[23:41:10.328] Running "vercel build"
[23:41:10.769] Vercel CLI 28.15.3
[23:41:10.992] Your application is being built using `next build`. If you need to define a different build step, please create a `vercel-build` script in your `package.json` (e.g. `{ "scripts": { "vercel-build": "npm run prepare && next build" } }`).
[23:41:10.994] Installing dependencies...
[23:41:11.290] yarn install v1.22.17
[23:41:11.310] warning package.json: No license field
[23:41:11.318] info No lockfile found.
[23:41:11.322] warning No license field
[23:41:11.323] [1/4] Resolving packages...
[23:41:11.324] [2/4] Fetching packages...
[23:41:11.324] [3/4] Linking dependencies...
[23:41:11.329] [4/4] Building fresh packages...
[23:41:11.332] success Saved lockfile.
[23:41:11.335] Done in 0.05s.
[23:41:11.399] Error: No Next.js version could be detected in your project. Make sure `"next"` is installed in "dependencies" or "devDependencies"

原始package.json

{
  "name": "portfolio_site",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@next/font": "13.1.1",
    "autoprefixer": "^10.4.13",
    "date-fns": "^2.29.3",
    "dotenv": "^16.0.3",
    "eslint": "8.31.0",
    "eslint-config-next": "13.1.1",
    "next": "^13.1.1",
    "next-themes": "^0.2.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-lottie-player": "^1.5.4"
  },
  "devDependencies": {
    "tailwindcss": "^3.2.4"
  },
  "scripts": {
  "start": "node_modules/next/dist/bin/next start -p $PORT"
  },
  "engines": {
       "node": "16.X"
  }
}

内容的提问来源于stack exchange,提问作者minsing-jin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 12:05:19