reactjs Vercel部署错误:命令“npm运行构建”退出,返回1

ulmd4ohb  于 2023-01-04  发布在  React
关注(0)|答案(5)|浏览(261)

我正在用VS代码开发一个React应用程序。我使用create-react-app进行设置。我可以使用npm start运行该项目,没有任何问题。当我尝试使用Vercel发布该项目时,我遇到错误:
已尝试再次删除node_modules和npm install

Error! Command "npm run build" exited with 1
Error! Check your logs at https://...

您可以查看下面的日志:

13:55:05.231    Retrieving list of deployment files...
13:55:06.975    Downloading 32 deployment files...
13:55:09.142    Analyzing source code...
13:55:11.289    Installing build runtime...
13:55:15.911    Build runtime installed: 4622.485ms
13:55:20.151    Looking up build cache...
13:55:21.237    Build cache not found
13:55:22.615    Detected package.json
13:55:22.616    Installing dependencies...
13:55:58.492    > core-js@2.6.12 postinstall /vercel/path0/node_modules/babel-runtime/node_modules/core-js
13:55:58.492    > node -e "try{require('./postinstall')}catch(e){}"
13:55:58.604    > core-js@3.9.1 postinstall /vercel/path0/node_modules/core-js
13:55:58.604    > node -e "try{require('./postinstall')}catch(e){}"
13:55:58.683    > core-js-pure@3.9.1 postinstall /vercel/path0/node_modules/core-js-pure
13:55:58.683    > node -e "try{require('./postinstall')}catch(e){}"
13:55:58.801    > ejs@2.7.4 postinstall /vercel/path0/node_modules/ejs
13:55:58.802    > node ./postinstall.js
13:56:01.182    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
13:56:01.182    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
13:56:01.191    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
13:56:01.191    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
13:56:01.202    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
13:56:01.202    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
13:56:01.210    added 1985 packages from 812 contributors in 37.99s
13:56:02.556    137 packages are looking for funding
13:56:02.556      run `npm fund` for details
13:56:02.831    Running "npm run build"
13:56:03.100    > last-letter-game@0.1.0 build /vercel/path0
13:56:03.100    > react-scripts build
13:56:04.846    Creating an optimized production build...
13:56:23.548    Treating warnings as errors because process.env.CI = true.
13:56:23.548    Most CI servers set it automatically.
13:56:23.548    Failed to compile.
13:56:23.549    src/components/Counter.js
13:56:23.549      Line 21:6:  React Hook useEffect has a missing dependency: 'props.timeEnds'. Either include it or remove the dependency array  react-hooks/exhaustive-deps
13:56:23.577    npm ERR! code ELIFECYCLE
13:56:23.578    npm ERR! errno 1
13:56:23.581    npm ERR! last-letter-game@0.1.0 build: `react-scripts build`
13:56:23.581    npm ERR! Exit status 1
13:56:23.583    npm ERR! 
13:56:23.583    npm ERR! Failed at the last-letter-game@0.1.0 build script.
13:56:23.583    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
13:56:23.592    npm ERR! A complete log of this run can be found in:
13:56:23.592    npm ERR!     /vercel/.npm/_logs/2021-03-28T10_56_23_582Z-debug.log
13:56:23.606    Error: Command "npm run build" exited with 1
xriantvc

xriantvc1#

检查您的代码是否没有任何warnings。如果它们有警告,请尝试修复它们并重新部署,或者通过将environment variableCI设置为false来忽略它们。

CI = false
5gfr0r5j

5gfr0r5j2#

如果出现此错误:
1.转到vercel.com中的项目设置。
1.去找将军。
1.在"构建和开发设置"中,重写构建命令并写入CI='' npm run build。这为我解决了错误。

sbtkgmzw

sbtkgmzw3#

使用Vercel CLI将CI环境变量设置为false

转到项目目录,然后打开终端并键入

$ vercel env add CI

Vercel CLI 24.0.0
? What’s the value of CLI? false
? Add CLI to which Environments (select multiple, press a)? Production, Preview, Development
✅  Added Environment Variable CLI to Project <Project-name> [776ms]

现在,转到Vercel应用程序=〉设置=〉环境变量,您将看到CLI键的值设置为false

nsc4cvqm

nsc4cvqm4#

您只需检查项目文件夹中的package.json,检查json对象中的构建脚本。

'script':
{
   "dev": "next dev",
             ==>  "build": "next build", 
    "start": "next start",
    "lint": "next lint"
}
qlzsbp2j

qlzsbp2j5#

"我是虔诚的"
对于部署,如果遇到错误,请按照以下过程操作...
1.在项目文件夹中运行yarn dev。
1.然后以管理员身份运行terminal,并cd到您的项目文件夹,然后运行vercel build命令。
1.成功完成后,删除.vercel\output\functions_next\data中的文件夹
1.然后运行vercel deploy prebuilt -〉successful(对我有效)

相关问题