为什么当我尝试部署我的Gatsby网站时得到错误消息?



我有一个盖茨比的应用。

当我在本地构建它时,它工作得很好,但是当我尝试将它部署到netflix或Gitlab时,我得到以下错误信息:Netlify错误信息:

8:44:20 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
8:44:20 PM: npm WARN config location in the cache, and they are managed by
8:44:20 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
8:44:20 PM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
8:44:20 PM: npm WARN config location in the cache, and they are managed by
8:44:20 PM: npm WARN config     [`cacache`](http://npm.im/cacache).
8:44:23 PM: npm ERR! code ERESOLVE
8:44:23 PM: npm ERR! ERESOLVE could not resolve
8:44:23 PM: npm ERR!
8:44:23 PM: npm ERR! While resolving: @mdx-js/react@1.6.22
8:44:23 PM: Creating deploy upload records
8:44:23 PM: npm ERR! Found: react@18.1.0
8:44:23 PM: npm ERR! node_modules/react
8:44:23 PM: npm ERR!   react@"^18.1.0" from the root project
8:44:23 PM: npm ERR!   peer react@"15.x || 16.x || 17.x || 18.x" from @gatsbyjs/reach-router@1.3.7
8:44:23 PM: npm ERR!   node_modules/@gatsbyjs/reach-router
8:44:23 PM: npm ERR!     @gatsbyjs/reach-router@"^1.3.6" from gatsby@4.17.1
8:44:23 PM: npm ERR!     node_modules/gatsby
8:44:23 PM: npm ERR!       gatsby@"^4.17.1" from the root project
8:44:24 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
8:44:23 PM: npm ERR!       13 more (babel-plugin-remove-graphql-queries, ...)
8:44:23 PM: npm ERR!     peer @gatsbyjs/reach-router@"^1.3.5" from gatsby-link@4.17.0
8:44:23 PM: npm ERR!     node_modules/gatsby-link
8:44:23 PM: npm ERR!       gatsby-link@"^4.17.0" from gatsby@4.17.1
8:44:23 PM: npm ERR!       node_modules/gatsby
8:44:23 PM: npm ERR!         gatsby@"^4.17.1" from the root project
8:44:23 PM: npm ERR!         13 more (babel-plugin-remove-graphql-queries, ...)
8:44:23 PM: npm ERR!     1 more (gatsby-react-router-scroll)
8:44:23 PM: npm ERR!   9 more (gatsby, gatsby-link, gatsby-plugin-image, ...)
8:44:23 PM: npm ERR!
8:44:23 PM: npm ERR! Could not resolve dependency:
8:44:23 PM: npm ERR! peer react@"^16.13.1 || ^17.0.0" from @mdx-js/react@1.6.22
8:44:23 PM: npm ERR! node_modules/@mdx-js/react
8:44:23 PM: npm ERR!   @mdx-js/react@"^1.6.22" from the root project
8:44:23 PM: npm ERR!   peer @mdx-js/react@"^1.0.0" from gatsby-plugin-mdx@3.17.0
8:44:23 PM: npm ERR!   node_modules/gatsby-plugin-mdx
8:44:23 PM: npm ERR!     gatsby-plugin-mdx@"^3.17.0" from the root project
8:44:23 PM: npm ERR!
8:44:23 PM: npm ERR! Conflicting peer dependency: react@17.0.2
8:44:23 PM: npm ERR! node_modules/react
8:44:23 PM: npm ERR!   peer react@"^16.13.1 || ^17.0.0" from @mdx-js/react@1.6.22
8:44:23 PM: npm ERR!   node_modules/@mdx-js/react
8:44:23 PM: npm ERR!     @mdx-js/react@"^1.6.22" from the root project
8:44:23 PM: npm ERR!     peer @mdx-js/react@"^1.0.0" from gatsby-plugin-mdx@3.17.0
8:44:23 PM: npm ERR!     node_modules/gatsby-plugin-mdx
8:44:23 PM: npm ERR!       gatsby-plugin-mdx@"^3.17.0" from the root project
8:44:23 PM: npm ERR!
8:44:23 PM: npm ERR! Fix the upstream dependency conflict, or retry
8:44:23 PM: npm ERR! this command with --force, or --legacy-peer-deps
8:44:23 PM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
8:44:23 PM: npm ERR!
8:44:23 PM: npm ERR! See /opt/buildhome/.npm/eresolve-report.txt for a full report.
8:44:23 PM: npm ERR! A complete log of this run can be found in:
8:44:23 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-06-25T17_44_20_693Z-debug-0.log
8:44:23 PM: Error during NPM install
8:44:23 PM: Build was terminated: Build script returned non-zero exit code: 1
8:44:23 PM: Failing build: Failed to build site
8:44:24 PM: Finished processing build request in 11.866525747s

Gitlab错误信息:

$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @mdx-js/react@1.6.22
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR!   peer react@"15.x || 16.x || 17.x || 18.x" from @gatsbyjs/reach-router@1.3.7
npm ERR!   node_modules/@gatsbyjs/reach-router
npm ERR!     @gatsbyjs/reach-router@"^1.3.6" from gatsby@4.17.1
npm ERR!     node_modules/gatsby
npm ERR!       gatsby@"^4.17.1" from the root project
npm ERR!       13 more (babel-plugin-remove-graphql-queries, ...)
npm ERR!     peer @gatsbyjs/reach-router@"^1.3.5" from gatsby-link@4.17.0
npm ERR!     node_modules/gatsby-link
npm ERR!       gatsby-link@"^4.17.0" from gatsby@4.17.1
npm ERR!       node_modules/gatsby
npm ERR!         gatsby@"^4.17.1" from the root project
npm ERR!         13 more (babel-plugin-remove-graphql-queries, ...)
npm ERR!     1 more (gatsby-react-router-scroll)
npm ERR!   9 more (gatsby, gatsby-link, gatsby-plugin-image, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.13.1 || ^17.0.0" from @mdx-js/react@1.6.22
npm ERR! node_modules/@mdx-js/react
npm ERR!   @mdx-js/react@"^1.6.22" from the root project
npm ERR!   peer @mdx-js/react@"^1.0.0" from gatsby-plugin-mdx@3.17.0
npm ERR!   node_modules/gatsby-plugin-mdx
npm ERR!     gatsby-plugin-mdx@"^3.17.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^16.13.1 || ^17.0.0" from @mdx-js/react@1.6.22
npm ERR!   node_modules/@mdx-js/react
npm ERR!     @mdx-js/react@"^1.6.22" from the root project
npm ERR!     peer @mdx-js/react@"^1.0.0" from gatsby-plugin-mdx@3.17.0
npm ERR!     node_modules/gatsby-plugin-mdx
npm ERR!       gatsby-plugin-mdx@"^3.17.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-06-25T18_16_56_033Z-debug-0.log
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

我以前部署过盖茨比站点,这次也没有什么不同。这个网站只是一个简单的页面,有一些CSS。

出现错误的原因是什么?

该错误是与react版本相关的对等依赖冲突,它提供了如何尝试解决它的指导:

npm犯错!修复上游依赖冲突,或者重试npm ERR!这命令中使用——force或——legacy-peer-deps。接受…不正确(并且可能损坏)的依赖解析。

在netflix上,你可以使用NPM_FLAGS环境变量。

最新更新