簡體   English   中英

Netlify 構建因 React 應用程序中的 npm 錯誤而失敗

[英]Netlify build failed for npm error in react app

這是來自 .netlify 構建日志的失敗構建日志。 我昨天建的。 現在我在構建網站時遇到問題

10:16:47 AM: Starting build script
10:16:47 AM: Installing dependencies
10:16:47 AM: Python version set to 2.7
10:16:47 AM: Downloading and installing node v16.15.1...
10:16:47 AM: Downloading https://nodejs.org/dist/v16.15.1/node-v16.15.1-linux-x64.tar.xz...
10:16:48 AM: Computing checksum with sha256sum
10:16:48 AM: Checksums matched!
10:16:51 AM: Now using node v16.15.1 (npm v8.11.0)
10:16:51 AM: Started restoring cached build plugins
10:16:51 AM: Finished restoring cached build plugins
10:16:51 AM: Attempting ruby version 2.7.2, read from environment
10:16:52 AM: Using ruby version 2.7.2
10:16:52 AM: Using PHP version 8.0
10:16:53 AM: No npm workspaces detected
10:16:53 AM: Started restoring cached node modules
10:16:53 AM: Finished restoring cached node modules
10:16:53 AM: Installing NPM modules using NPM version 8.11.0
10:16:54 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:16:54 AM: npm WARN config location in the cache, and they are managed by
10:16:54 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:16:54 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
10:16:54 AM: npm WARN config location in the cache, and they are managed by
10:16:54 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
10:16:56 AM: npm ERR! code ERESOLVE
10:16:56 AM: npm ERR! ERESOLVE could not resolve
10:16:56 AM: npm ERR!
10:16:56 AM: npm ERR! While resolving: react-reveal@1.2.2
10:16:56 AM: Creating deploy upload records
10:16:56 AM: npm ERR! Found: react@17.0.2
10:16:56 AM: npm ERR! node_modules/react
10:16:56 AM: npm ERR!   react@"^17.0.2" from the root project
10:16:56 AM: npm ERR!   peer react@">= 16.8.0" from @formspree/react@2.2.4
10:16:56 AM: npm ERR!   node_modules/@formspree/react
10:16:57 AM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
10:16:56 AM: npm ERR!     @formspree/react@"^2.2.4" from the root project
10:16:56 AM: npm ERR!   8 more (@testing-library/react, react-dom, react-icons, ...)
10:16:56 AM: npm ERR!
10:16:56 AM: npm ERR! Could not resolve dependency:
10:16:56 AM: npm ERR! peer react@"^15.3.0 || ^16.0.0" from react-reveal@1.2.2
10:16:56 AM: npm ERR! node_modules/react-reveal
10:16:56 AM: npm ERR!   react-reveal@"^1.2.2" from the root project
10:16:56 AM: npm ERR!
10:16:56 AM: npm ERR! Conflicting peer dependency: react@16.14.0
10:16:56 AM: npm ERR! node_modules/react
10:16:56 AM: npm ERR!   peer react@"^15.3.0 || ^16.0.0" from react-reveal@1.2.2
10:16:56 AM: npm ERR!   node_modules/react-reveal
10:16:56 AM: npm ERR!     react-reveal@"^1.2.2" from the root project
10:16:56 AM: npm ERR!
10:16:56 AM: npm ERR! Fix the upstream dependency conflict, or retry
10:16:56 AM: npm ERR! this command with --force, or --legacy-peer-deps
10:16:56 AM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
10:16:56 AM: npm ERR!
10:16:56 AM: npm ERR! See /opt/buildhome/.npm/eresolve-report.txt for a full report.
10:16:56 AM: npm ERR! A complete log of this run can be found in:
10:16:56 AM: npm ERR!     /opt/buildhome/.npm/_logs/2022-06-14T04_16_54_367Z-debug-0.log
10:16:56 AM: Error during NPM install
10:16:56 AM: Build was terminated: Build script returned non-zero exit code: 1
10:16:57 AM: Failing build: Failed to build site
10:16:57 AM: Finished processing build request in 13.567112014s

我猜這可能是 NPM。我應該刪除我安裝的依賴項並再次使用 --force 標志重新安裝它們嗎? 我正在使用 npm 版本 8。我該如何解決這個問題?

我在部署到 Netlify 時遇到了同樣的問題,對我的 PR 的所有檢查都失敗了。 經過一番搜索后,找到了 Netlify 論壇中提到的解決方案 - Fix for Build was terminated: Build script returned non-zero exit code: 1

就我而言,我能夠通過在構建命令npm run build --force之后添加--force標志來解決問題。 此外,必須在NODE_VERSION env 變量設置為16.15.0 ,因為顯然問題發生在 Node 版本16.15.1中,而該版本正是用於構建的版本。

這與您的帖子中提到的節點版本相同 -

上午 10:16:51:現在使用節點 v16.15.1 (npm v8.11.0)

如果我使用的解決方案不適合您,則上面提供的鏈接中也提到了其他一些解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM