netlify 部署:'building site' 阶段失败:构建脚本返回非零退出代码:2
netlify deployment: Failed during stage 'building site': Build script returned non-zero exit code: 2
我正在尝试通过 Github 将我的 reactjs 站点部署到 Netlify,但没有成功。
错误信息是
Failed during stage 'building site': Build script returned non-zero
exit code: 2
以下是完整的 Netlify 日志。
11:59:46 AM: Build ready to start
11:59:48 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
11:59:48 AM: build-image tag: v3.4.1
11:59:48 AM: buildbot version: 0a44c930054be748eff0c581d346282fece89cc0
11:59:48 AM: Building without cache
11:59:48 AM: Starting to prepare the repo for build
11:59:48 AM: No cached dependencies found. Cloning fresh repo
11:59:48 AM: git clone https://github.com/Helloiain/movie-app
11:59:49 AM: Preparing Git Reference refs/heads/master
11:59:50 AM: Starting build script
11:59:50 AM: Installing dependencies
11:59:50 AM: Python version set to 2.7
11:59:51 AM: v12.18.0 is already installed.
11:59:52 AM: Now using node v12.18.0 (npm v6.14.4)
11:59:52 AM: Started restoring cached build plugins
11:59:52 AM: Finished restoring cached build plugins
11:59:52 AM: Attempting ruby version 2.7.1, read from environment
11:59:53 AM: Using ruby version 2.7.1
11:59:54 AM: Using PHP version 5.6
11:59:54 AM: 5.2 is already installed.
11:59:54 AM: Using Swift version 5.2
11:59:54 AM: Started restoring cached node modules
11:59:54 AM: Finished restoring cached node modules
11:59:54 AM: Started restoring cached yarn cache
11:59:54 AM: Finished restoring cached yarn cache
11:59:54 AM: Installing yarn at version 1.22.4
11:59:54 AM: Installing Yarn!
11:59:54 AM: > Downloading tarball...
11:59:54 AM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.aq7yGqZqlV
11:59:54 AM: % Total % Received % Xferd Average Speed Time Time Time Current
11:59:54 AM: Dload Upload Total Spent Left Speed
11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:54 AM: 100 80 100 80 0 0 285 0 --:--:-- --:--:-- --:--:-- 285
11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:54 AM: 100 93 100 93 0 0 156 0 --:--:-- --:--:-- --:--:-- 556
11:59:55 AM: 100 643 100 643 0 0 749 0 --:--:-- --:--:-- --:--:-- 749
11:59:55 AM: 100 1215k 100 1215k 0 0 947k 0 0:00:01 0:00:01 --:--:-- 947k
11:59:55 AM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.aq7yGqZqlV.asc
11:59:55 AM: 100 84 100 84 0 0 3088 0 --:--:-- --:--:-- --:--:-- 3088
11:59:55 AM: 100 97 100 97 0 0 1692 0 --:--:-- --:--:-- --:--:-- 1692
11:59:55 AM: 100 647 100 647 0 0 7321 0 --:--:-- --:--:-- --:--:-- 7321
11:59:55 AM: 0 1028 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:55 AM: 100 1028 100 1028 0 0 8135 0 --:--:-- --:--:-- --:--:-- 1003k
11:59:55 AM: > Verifying integrity...
11:59:55 AM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
11:59:55 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
11:59:55 AM: gpg: WARNING: This key is not certified with a trusted signature!
11:59:55 AM: gpg: There is no indication that the signature belongs to the owner.
11:59:55 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
11:59:55 AM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
11:59:55 AM: > GPG signature looks good
11:59:55 AM: > Extracting to ~/.yarn...
11:59:55 AM: > Adding to $PATH...
11:59:56 AM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
11:59:56 AM: Installing NPM modules using Yarn version 1.22.4
11:59:57 AM: yarn install v1.22.4
11:59:57 AM: [1/4] Resolving packages...
11:59:58 AM: [2/4] Fetching packages...
12:00:22 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
12:00:22 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
12:00:22 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
12:00:22 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
12:00:22 PM: [3/4] Linking dependencies...
12:00:22 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
12:00:22 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
12:00:34 PM: [4/4] Building fresh packages...
12:00:36 PM: success Saved lockfile.
12:00:36 PM: Done in 38.98s.
12:00:36 PM: NPM modules installed using Yarn
12:00:36 PM: Started restoring cached go cache
12:00:36 PM: Finished restoring cached go cache
12:00:36 PM: go version go1.14.4 linux/amd64
12:00:36 PM: go version go1.14.4 linux/amd64
12:00:36 PM: Installing missing commands
12:00:36 PM: Verify run directory
12:00:37 PM:
12:00:37 PM: ┌─────────────────────────────┐
12:00:37 PM: │ Netlify Build │
12:00:37 PM: └─────────────────────────────┘
12:00:37 PM:
12:00:37 PM: ❯ Version
12:00:37 PM: @netlify/build 5.0.2
12:00:37 PM:
12:00:37 PM: ❯ Flags
12:00:37 PM: deployId: 5f9069020af24e00933f58d3
12:00:37 PM: mode: buildbot
12:00:37 PM:
12:00:37 PM: ❯ Current directory
12:00:37 PM: /opt/build/repo
12:00:37 PM:
12:00:37 PM: ❯ Config file
12:00:37 PM: No config file was defined: using default values.
12:00:37 PM:
12:00:37 PM: ❯ Context
12:00:37 PM: production
12:00:37 PM:
12:00:37 PM: ┌───────────────────────────────────┐
12:00:37 PM: │ 1. Build command from Netlify app │
12:00:37 PM: └───────────────────────────────────┘
12:00:37 PM:
12:00:37 PM: $ yarn build
12:00:38 PM: yarn run v1.22.4
12:00:38 PM: $ react-scripts build
12:00:39 PM: Creating an optimized production build...
12:00:41 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
12:00:42 PM: Failed to compile.
12:00:42 PM:
12:00:42 PM: ./src/index.js
12:00:42 PM: Cannot find file './app.js' in './src'.
12:00:42 PM: error Command failed with exit code 1.
12:00:42 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:00:42 PM:
12:00:42 PM: ┌─────────────────────────────┐
12:00:42 PM: │ "build.command" failed │
12:00:42 PM: └─────────────────────────────┘
12:00:42 PM:
12:00:42 PM: Error message
12:00:42 PM: Command failed with exit code 1: yarn build
12:00:42 PM:
12:00:42 PM: Error location
12:00:42 PM: In Build command from Netlify app:
12:00:42 PM: yarn build
12:00:42 PM:
12:00:42 PM: Resolved config
12:00:42 PM: build:
12:00:42 PM: command: yarn build
12:00:42 PM: commandOrigin: ui
12:00:42 PM: publish: /opt/build/repo/build
12:00:42 PM: Caching artifacts
12:00:42 PM: Started saving node modules
12:00:42 PM: Finished saving node modules
12:00:42 PM: Started saving build plugins
12:00:42 PM: Finished saving build plugins
12:00:42 PM: Started saving yarn cache
12:00:42 PM: Finished saving yarn cache
12:00:42 PM: Started saving pip cache
12:00:42 PM: Finished saving pip cache
12:00:42 PM: Started saving emacs cask dependencies
12:00:42 PM: Finished saving emacs cask dependencies
12:00:42 PM: Started saving maven dependencies
12:00:42 PM: Finished saving maven dependencies
12:00:42 PM: Started saving boot dependencies
12:00:42 PM: Finished saving boot dependencies
12:00:42 PM: Started saving go dependencies
12:00:42 PM: Finished saving go dependencies
12:00:45 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:00:45 PM: Failing build: Failed to build site
12:00:45 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:00:45 PM: Finished processing build request in 57.736891768s
搜索过类似的问题,我认为这可能是依赖问题,但是,在使用'Yarn'安装依赖项后,我仍然遇到同样的问题。并且使用“yarn build”在本地构建工作正常。
想通了。原来是app.js的大小写,我只好改成了App.js,
您必须更改环境变量值才能成功构建。按照以下步骤操作:
- 转到
Deploy settings
。
- 单击
Environment
,然后单击 Edit Variables
按钮。
- 将 Key 设置为
CI
,将 Value 设置为 false
。
- 现在点击
Save
按钮。
现在您可以构建和部署您的项目而不会出现错误。
我在尝试将我的单页 React JS Web 应用程序部署到 Netlify 时发现了同样的错误。
以下是我解决问题并成功部署站点所遵循的过程。
转到站点设置。
Select 构建和部署 下拉菜单。
Select 持续部署 选项卡。
在 Build Settings 部分下,Select Edit settings.
- 将构建命令更改为
CI= npm run build
- 单击保存。
然后是 select 环境 选项卡。
- Select 编辑变量.
- 作为 Key 输入
CI
并且作为 value输入false
.
- 单击保存。
终于再次尝试部署站点。
这将帮助您解决与在 Netlify 中托管 'Rect JS' 应用程序相关的问题,您的应用程序将成功部署。
我也遇到了同样的错误,但是我的错误用这个命令清除了
CI= npm 运行 构建,但是我又一次遇到了同样的错误然后尝试了这个但是这次它不起作用但是我通过以下方法解决了这个问题:
- 检查你推送的代码是否存在(github,bitbucket.. 随便)
- 如果部署失败尝试还原推送并再次尝试使用
CI= npm 运行 构建,如果失败也创建另一个(新提交推送)部署
- 在我的例子中,在执行上述程序后它失败了 5 次,它工作得很好
这个错误大部分是由于构建缓存和时间错误造成的
我收到这个错误是因为我有一个编译错误,但我不知道,因为未暂存的本地更改将它隐藏在我的本地环境中。
在我的例子中 newFile.js
还没有提交。但是 newFile.js
被导入了 committedFile.js
。由于 newFile.js
未提交,构建无法编译,没有可导入到 committedFile.js
.
的文件
执行此操作以查看是否存在隐藏的编译错误:
使用 git stash -u
隐藏本地未提交的更改,并查看您是否在本地遇到编译错误。
我正在尝试通过 Github 将我的 reactjs 站点部署到 Netlify,但没有成功。
错误信息是
Failed during stage 'building site': Build script returned non-zero exit code: 2
以下是完整的 Netlify 日志。
11:59:46 AM: Build ready to start
11:59:48 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
11:59:48 AM: build-image tag: v3.4.1
11:59:48 AM: buildbot version: 0a44c930054be748eff0c581d346282fece89cc0
11:59:48 AM: Building without cache
11:59:48 AM: Starting to prepare the repo for build
11:59:48 AM: No cached dependencies found. Cloning fresh repo
11:59:48 AM: git clone https://github.com/Helloiain/movie-app
11:59:49 AM: Preparing Git Reference refs/heads/master
11:59:50 AM: Starting build script
11:59:50 AM: Installing dependencies
11:59:50 AM: Python version set to 2.7
11:59:51 AM: v12.18.0 is already installed.
11:59:52 AM: Now using node v12.18.0 (npm v6.14.4)
11:59:52 AM: Started restoring cached build plugins
11:59:52 AM: Finished restoring cached build plugins
11:59:52 AM: Attempting ruby version 2.7.1, read from environment
11:59:53 AM: Using ruby version 2.7.1
11:59:54 AM: Using PHP version 5.6
11:59:54 AM: 5.2 is already installed.
11:59:54 AM: Using Swift version 5.2
11:59:54 AM: Started restoring cached node modules
11:59:54 AM: Finished restoring cached node modules
11:59:54 AM: Started restoring cached yarn cache
11:59:54 AM: Finished restoring cached yarn cache
11:59:54 AM: Installing yarn at version 1.22.4
11:59:54 AM: Installing Yarn!
11:59:54 AM: > Downloading tarball...
11:59:54 AM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.aq7yGqZqlV
11:59:54 AM: % Total % Received % Xferd Average Speed Time Time Time Current
11:59:54 AM: Dload Upload Total Spent Left Speed
11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:54 AM: 100 80 100 80 0 0 285 0 --:--:-- --:--:-- --:--:-- 285
11:59:54 AM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:54 AM: 100 93 100 93 0 0 156 0 --:--:-- --:--:-- --:--:-- 556
11:59:55 AM: 100 643 100 643 0 0 749 0 --:--:-- --:--:-- --:--:-- 749
11:59:55 AM: 100 1215k 100 1215k 0 0 947k 0 0:00:01 0:00:01 --:--:-- 947k
11:59:55 AM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.aq7yGqZqlV.asc
11:59:55 AM: 100 84 100 84 0 0 3088 0 --:--:-- --:--:-- --:--:-- 3088
11:59:55 AM: 100 97 100 97 0 0 1692 0 --:--:-- --:--:-- --:--:-- 1692
11:59:55 AM: 100 647 100 647 0 0 7321 0 --:--:-- --:--:-- --:--:-- 7321
11:59:55 AM: 0 1028 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
11:59:55 AM: 100 1028 100 1028 0 0 8135 0 --:--:-- --:--:-- --:--:-- 1003k
11:59:55 AM: > Verifying integrity...
11:59:55 AM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA
11:59:55 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
11:59:55 AM: gpg: WARNING: This key is not certified with a trusted signature!
11:59:55 AM: gpg: There is no indication that the signature belongs to the owner.
11:59:55 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907 BBB7 1646 B01B 86E5 0310
11:59:55 AM: Subkey fingerprint: 6D98 490C 6F1A CDDD 448E 4595 4F77 6793 6947 5BAA
11:59:55 AM: > GPG signature looks good
11:59:55 AM: > Extracting to ~/.yarn...
11:59:55 AM: > Adding to $PATH...
11:59:56 AM: > Successfully installed Yarn 1.22.4! Please open another terminal where the `yarn` command will now be available.
11:59:56 AM: Installing NPM modules using Yarn version 1.22.4
11:59:57 AM: yarn install v1.22.4
11:59:57 AM: [1/4] Resolving packages...
11:59:58 AM: [2/4] Fetching packages...
12:00:22 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
12:00:22 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
12:00:22 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
12:00:22 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
12:00:22 PM: [3/4] Linking dependencies...
12:00:22 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
12:00:22 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
12:00:34 PM: [4/4] Building fresh packages...
12:00:36 PM: success Saved lockfile.
12:00:36 PM: Done in 38.98s.
12:00:36 PM: NPM modules installed using Yarn
12:00:36 PM: Started restoring cached go cache
12:00:36 PM: Finished restoring cached go cache
12:00:36 PM: go version go1.14.4 linux/amd64
12:00:36 PM: go version go1.14.4 linux/amd64
12:00:36 PM: Installing missing commands
12:00:36 PM: Verify run directory
12:00:37 PM:
12:00:37 PM: ┌─────────────────────────────┐
12:00:37 PM: │ Netlify Build │
12:00:37 PM: └─────────────────────────────┘
12:00:37 PM:
12:00:37 PM: ❯ Version
12:00:37 PM: @netlify/build 5.0.2
12:00:37 PM:
12:00:37 PM: ❯ Flags
12:00:37 PM: deployId: 5f9069020af24e00933f58d3
12:00:37 PM: mode: buildbot
12:00:37 PM:
12:00:37 PM: ❯ Current directory
12:00:37 PM: /opt/build/repo
12:00:37 PM:
12:00:37 PM: ❯ Config file
12:00:37 PM: No config file was defined: using default values.
12:00:37 PM:
12:00:37 PM: ❯ Context
12:00:37 PM: production
12:00:37 PM:
12:00:37 PM: ┌───────────────────────────────────┐
12:00:37 PM: │ 1. Build command from Netlify app │
12:00:37 PM: └───────────────────────────────────┘
12:00:37 PM:
12:00:37 PM: $ yarn build
12:00:38 PM: yarn run v1.22.4
12:00:38 PM: $ react-scripts build
12:00:39 PM: Creating an optimized production build...
12:00:41 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
12:00:42 PM: Failed to compile.
12:00:42 PM:
12:00:42 PM: ./src/index.js
12:00:42 PM: Cannot find file './app.js' in './src'.
12:00:42 PM: error Command failed with exit code 1.
12:00:42 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
12:00:42 PM:
12:00:42 PM: ┌─────────────────────────────┐
12:00:42 PM: │ "build.command" failed │
12:00:42 PM: └─────────────────────────────┘
12:00:42 PM:
12:00:42 PM: Error message
12:00:42 PM: Command failed with exit code 1: yarn build
12:00:42 PM:
12:00:42 PM: Error location
12:00:42 PM: In Build command from Netlify app:
12:00:42 PM: yarn build
12:00:42 PM:
12:00:42 PM: Resolved config
12:00:42 PM: build:
12:00:42 PM: command: yarn build
12:00:42 PM: commandOrigin: ui
12:00:42 PM: publish: /opt/build/repo/build
12:00:42 PM: Caching artifacts
12:00:42 PM: Started saving node modules
12:00:42 PM: Finished saving node modules
12:00:42 PM: Started saving build plugins
12:00:42 PM: Finished saving build plugins
12:00:42 PM: Started saving yarn cache
12:00:42 PM: Finished saving yarn cache
12:00:42 PM: Started saving pip cache
12:00:42 PM: Finished saving pip cache
12:00:42 PM: Started saving emacs cask dependencies
12:00:42 PM: Finished saving emacs cask dependencies
12:00:42 PM: Started saving maven dependencies
12:00:42 PM: Finished saving maven dependencies
12:00:42 PM: Started saving boot dependencies
12:00:42 PM: Finished saving boot dependencies
12:00:42 PM: Started saving go dependencies
12:00:42 PM: Finished saving go dependencies
12:00:45 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:00:45 PM: Failing build: Failed to build site
12:00:45 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
12:00:45 PM: Finished processing build request in 57.736891768s
搜索过类似的问题,我认为这可能是依赖问题,但是,在使用'Yarn'安装依赖项后,我仍然遇到同样的问题。并且使用“yarn build”在本地构建工作正常。
想通了。原来是app.js的大小写,我只好改成了App.js,
您必须更改环境变量值才能成功构建。按照以下步骤操作:
- 转到
Deploy settings
。 - 单击
Environment
,然后单击Edit Variables
按钮。 - 将 Key 设置为
CI
,将 Value 设置为false
。 - 现在点击
Save
按钮。
现在您可以构建和部署您的项目而不会出现错误。
我在尝试将我的单页 React JS Web 应用程序部署到 Netlify 时发现了同样的错误。
以下是我解决问题并成功部署站点所遵循的过程。
转到站点设置。
Select 构建和部署 下拉菜单。
Select 持续部署 选项卡。
在 Build Settings 部分下,Select Edit settings.
- 将构建命令更改为
CI= npm run build
- 单击保存。
- 将构建命令更改为
然后是 select 环境 选项卡。
- Select 编辑变量.
- 作为 Key 输入
CI
并且作为 value输入false
. - 单击保存。
终于再次尝试部署站点。
这将帮助您解决与在 Netlify 中托管 'Rect JS' 应用程序相关的问题,您的应用程序将成功部署。
我也遇到了同样的错误,但是我的错误用这个命令清除了 CI= npm 运行 构建,但是我又一次遇到了同样的错误然后尝试了这个但是这次它不起作用但是我通过以下方法解决了这个问题:
- 检查你推送的代码是否存在(github,bitbucket.. 随便)
- 如果部署失败尝试还原推送并再次尝试使用 CI= npm 运行 构建,如果失败也创建另一个(新提交推送)部署
- 在我的例子中,在执行上述程序后它失败了 5 次,它工作得很好
这个错误大部分是由于构建缓存和时间错误造成的
我收到这个错误是因为我有一个编译错误,但我不知道,因为未暂存的本地更改将它隐藏在我的本地环境中。
在我的例子中 newFile.js
还没有提交。但是 newFile.js
被导入了 committedFile.js
。由于 newFile.js
未提交,构建无法编译,没有可导入到 committedFile.js
.
执行此操作以查看是否存在隐藏的编译错误:
使用 git stash -u
隐藏本地未提交的更改,并查看您是否在本地遇到编译错误。