- Expected Outcome: Things should go as defined in the tutorial guide
- Actual Outcome: Getting Dependency tree error in step(s) & Also a warning message like `34 vulnerabilities (11 moderate, 23 high)` whenever installing something using npm in this project问题:
Command-used: npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1
Output/Console Error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-gatsby-site@1.0.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR! react@"^18.1.0" from the root project
npm ERR! peer react@"^16.9.0 || ^17.0.0 || ^18.0.0" from gatsby-plugin-mdx@3.18.0
npm ERR! node_modules/gatsby-plugin-mdx
npm ERR! gatsby-plugin-mdx@"*" from the root project
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@"v1" from the root project
npm ERR! peer @mdx-js/react@"^1.0.0" from gatsby-plugin-mdx@3.18.0
npm ERR! node_modules/gatsby-plugin-mdx
npm ERR! gatsby-plugin-mdx@"*" 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 <home-folder>/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! <home-folder>/.npm/_logs/2022-07-06T15_46_56_149Z-debug-0.log更新:
更新1:
在尝试了另一个堆栈溢出站点成员的建议后,将引发一个新的错误!因此,忽略跳转遗留树的依赖树问题是行不通的,因此任何gatsby用户都会提出更多建议!?
gatsby develop
ERROR #11901 COMPILATION
Failed to compile Gatsby files (Error):
Could not resolve module "@parcel/namer-default" from
"<home-folder>/codeSpace/siteByGatsby/sv3/my-gatsby-site/node\_modules/@gatsbyjs/parcel-namer-relative-to-cwd/lib/index.js".
not finished compile gatsby files - 0.778s发布于 2022-07-06 19:28:38
不是说“你应该”通常按我的建议去做,但你可以跑:
npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1 --legacy-peer-deps基本上,这样做的目的是告诉npm您希望安装对等依赖项,原因是在您的项目中使用了React@18.2,但是您试图安装的包使用的是一个较低版本的peer。因此,NPM正在向您抛出此错误。
通常情况下,“您不应该”这样做的原因是,假设包中有一个依赖项被标记为不可维护,但是您现在已经安装了一个‘固定’版本。然后,您将安装可能具有低俗性的对等依赖关系。
您可以运行上述代码,并‘好’,这不是什么大不了的,它是想安装较小版本的反应。
但是,您还应该考虑的是,您真的需要React@18.2,还是可以使用降级版本,因为您使用最新版本中的任何特性的可能性有多大。
这也是为什么许多开发人员在构建项目时不只是安装Reacts的最新版本,因为您必须依赖由单人开发人员维护的软件包,或者由愿意帮助维护软件包的可爱人员社区维护,以使其与React最新版本同步。
这是你可以做的主要三件事:
希望这会有所帮助:)
西德诺特:
在将此项目迁移到宿主提供商时,您还需要告诉他们,您已经在--legacy-peer-deps中强制安装了包,方法是在宿主提供商平台上为站点创建一个环境变量,或者使用.npmrc文件,其中包含以下内容:
legacy-peer-deps=truehttps://stackoverflow.com/questions/72887003
复制相似问题