获取:构建脚本返回了非零的退出代码:1
我已经通过Netlify部署了我的react js网站代码,并得到了如下的构建日志和错误:
10:37:15 AM: Build ready to start
10:37:16 AM: build-image version: 42bca793ccd33055023c56c4ca8510463a56d317
10:37:17 AM: buildbot version: 6bab8b64bbd90091082af19fedf16bf73d502e5e
10:37:17 AM: Fetching cached dependencies
10:37:17 AM: Failed to fetch cache, continuing with build
10:37:17 AM: Starting to prepare the repo for build
10:37:17 AM: No cached dependencies found. Cloning fresh repo
10:37:17 AM: git clone git@github.com:justtabhi/react-blog-exambunker
10:37:19 AM: Preparing Git Reference refs/heads/master
10:37:20 AM: Starting build script
10:37:20 AM: Installing dependencies
10:37:21 AM: Downloading and installing node v8.12.0...
10:37:21 AM: Downloading https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.xz...
10:37:21 AM:
#
10:37:21 AM: 1.6%
10:37:22 AM:
#############################
10:37:22 AM: 40.8%
10:37:22 AM:
#####################################
10:37:22 AM: ################################### 100.0%
10:37:22 AM: Computing checksum with sha256sum
10:37:22 AM: Checksums matched!
10:37:24 AM: Now using node v8.12.0 (npm v6.4.1)
10:37:24 AM: Attempting ruby version 2.3.6, read from environment
10:37:25 AM: Using ruby version 2.3.6
10:37:26 AM: Using PHP version 5.6
10:37:26 AM: Started restoring cached node modules
10:37:26 AM: Finished restoring cached node modules
10:37:26 AM: Installing NPM modules using NPM version 6.4.1
10:37:53 AM: > uglifyjs-webpack-plugin@0.4.6 postinstall
/opt/build/repo/node_modules/uglifyjs-webpack-plugin
10:37:53 AM: > node lib/post_install.js
10:37:55 AM: npm
10:37:55 AM: WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
10:37:55 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:37:55 AM: added 1280 packages from 735 contributors and audited 12827
packages in 28.118s
10:37:55 AM: found 0 vulnerabilities
10:37:55 AM: NPM modules installed
10:37:55 AM: Started restoring cached go cache
10:37:55 AM: Finished restoring cached go cache
10:37:55 AM: unset GOOS;
10:37:55 AM: unset GOARCH;
10:37:55 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
10:37:55 AM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
10:37:55 AM: go version >&2;
10:37:55 AM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
10:37:55 AM: go version go1.10 linux/amd64
10:37:55 AM: Installing missing commands
10:37:55 AM: Verify run directory
10:37:55 AM: Executing user command: npm run build
10:37:55 AM: > react-blog@0.1.0 build /opt/build/repo
10:37:55 AM: > react-scripts build`enter code here`
10:37:57 AM: Creating an optimized production build...
10:38:02 AM: Failed to compile.
10:38:02 AM: Failed to minify the code from this file:
10:38:02 AM: ./node_modules/indicative/builds/main.js:1:52673
10:38:02 AM: npm ERR! code ELIFECYCLE
10:38:02 AM: npm ERR! errno 1
10:38:02 AM: npm ERR! react-blog@0.1.0 build: `react-scripts build`
10:38:02 AM: npm ERR! Exit status 1
10:38:02 AM: npm ERR!
10:38:02 AM: npm ERR! Failed at the react-blog@0.1.0 build script.
10:38:02 AM: npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
10:38:02 AM: npm ERR! A complete log of this run can be found in:
10:38:02 AM: npm ERR! /opt/buildhome/.npm/_logs/2018-09-25T05_08_02_457Z-
debug.log
10:38:02 AM: Caching artifacts
10:38:02 AM: Started saving node modules
10:38:02 AM: Finished saving node modules
10:38:02 AM: Started saving pip cache
10:38:02 AM: Finished saving pip cache
10:38:02 AM: Started saving emacs cask dependencies
10:38:02 AM: Finished saving emacs cask dependencies
10:38:02 AM: Started saving maven dependencies
10:38:02 AM: Finished saving maven dependencies
10:38:02 AM: Started saving boot dependencies
10:38:02 AM: Finished saving boot dependencies
10:38:02 AM: Started saving go dependencies
10:38:02 AM: Finished saving go dependencies
10:38:03 AM: Cached node version v8.12.0
10:38:03 AM: Error running command: Build script returned non-zero exit code: 1
10:38:03 AM: Failing build: Failed to build site
10:38:03 AM: failed during stage 'building site': Build script returned non-zero
exit code: 1
10:38:03 AM: Finished processing build request in 46.262986678s
请有人建议这里可能出了什么问题?
答案 0 :(得分:2)
此处的问题是由react-scripts
中使用create-react-app
的构建环境引起的。您有一个node_modules
软件包正在导入,该软件包采用了意外的捆绑格式。
在本地开发中运行npm run build
时(这是Netlify上发生的事情),您会在构建时看到以下错误:
Failed to minify the code from this file:
./node_modules/indicative/builds/main.js:1:52673
Read more here: http:// bit.ly/2tRViJ9
如链接(http:// bit.ly/2tRViJ9)所述,react-scripts
需要升级到react-scripts @> = 2.0.0
$ npm install react-scripts@^2.0.0
在先前的版本(<2.0.0)中,react-scripts
不支持ES。node_modules
中的ES.Next功能。它期望使用CommonJS或ES,并建议针对较旧的浏览器编译为ES5。现在,该版本将允许您设置目标浏览器并使用ES.Next功能。
一旦确认构建本地没有错误,就可以将这些更改推送到git存储库中,并且Netlify构建也应该起作用。
注意::在将Netlify用作CI / CD解决方案时,最好先确保在本地开发期间运行build命令,然后再将更改推送到主目标分支以进行更改。确保您的生产版本没有任何问题。