命令失败,退出代码 1:CI= npm run build

时间:2021-05-05 00:23:00

标签: node.js express deployment netlify

我一直在为这件事发疯
我已使用 this 视频作为参考,但仍然出现以下错误
我已经尝试了从 Netlify FormyoutubeStackoverflow

的所有内容
5:33:23 AM: ────────────────────────────────────────────────────────────────
5:33:23 AM:   "build.command" failed                                        
5:33:23 AM: ────────────────────────────────────────────────────────────────
5:33:23 AM: ​
5:33:23 AM:   Error message
5:33:23 AM:   Command failed with exit code 1: CI= npm run build
5:33:23 AM: ​
5:33:23 AM:   Error location
5:33:23 AM:   In Build command from Netlify app:
5:33:23 AM:   CI= npm run build
5:33:23 AM: ​
5:33:23 AM:   Resolved config
5:33:23 AM:   build:
5:33:23 AM:     command: CI= npm run build
5:33:23 AM:     commandOrigin: ui
5:33:23 AM:     publish: /opt/build/repo/dist

我的 package.json 文件

{
  "name": "testing",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "./node_modules/.bin/netlify-lambda serve src",
    "build": "CI= npm run build"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/<my-username>/testing.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/<my-username>/testing/issues"
  },
  "homepage": "https://github.com/<my-username>/testing#readme",
  "dependencies": {
    "express": "^4.17.1",
    "netlify-lambda": "^2.0.6",
    "serverless-http": "^2.7.0"
  }
}

我的 netlify.toml

[build]

functions = "functions"

部署设置 enter image description here

我错过了什么?请帮助我为此脱发

2 个答案:

答案 0 :(得分:0)

我遇到了类似的错误,我发现以下已修复它。

首先在 package.json 中,您必须将构建脚本更改为 "build": "react-scripts build"

应该是:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "./node_modules/.bin/netlify-lambda serve src",
  "build": "react-scripts build"
},

并且在您的 netlify 部署设置中更改为 CI= npm build。

并确保您的发布文件夹存在。

答案 1 :(得分:0)

通常,选择因警告而失败的库假定其用户希望修复导致警告的问题。如果这对您的用例不切实际,您可以通过在站点构建命令的开头添加 CI='' 来覆盖 CI 变量。例如:

CI='' npm run build

这解决了我自己的类似问题