![](/img/trans.png)
[英]Error fetch from react to express without CRA(create-react-app)
[英]Netlify build Error using create-react-app (CRA) website
獲取:構建腳本返回非零退出代碼: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
請有人建議這里可能出了什么問題?
這里的問題是由在create-react-app
使用react-scripts
的構建環境引起的。 您正在導入一個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.Next特征發現node_modules
。 它期望使用 CommonJS 或 ES,並建議為舊瀏覽器編譯為 ES5。 現在構建將允許您設置目標瀏覽器並使用 ES.Next 功能。
一旦您確認構建本地沒有錯誤,您就可以將這些更改推送到您的 git 存儲庫,並且您的 Netlify 構建也應該可以工作。
注意:使用 Netlify 作為 CI/CD 解決方案時,在將更改推送到主目標分支之前確保在本地開發期間運行構建命令是一個很好的做法,以確保您的生產構建沒有任何問題.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.