首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在gatsby站点中安装和配置MDX转换器插件(和依赖项)

无法在gatsby站点中安装和配置MDX转换器插件(和依赖项)
EN

Stack Overflow用户
提问于 2022-07-06 16:29:39
回答 1查看 209关注 0票数 3
  • 目标:尝试使用盖茨比创建一个简单的博客
  • 成果:
代码语言:javascript
复制
- 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

问题:

  1. 我如何解决这个特定的依赖树问题&通常我如何处理npm中的这类错误(依赖树问题)?
  2. 与易受攻击包相关的警告--这些警告有多重要--应该如何处理?
代码语言:javascript
复制
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用户都会提出更多建议!?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2022-07-06 19:28:38

不是说“你应该”通常按我的建议去做,但你可以跑:

代码语言:javascript
复制
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最新版本同步。

这是你可以做的主要三件事:

  • 您可以安装遗留依赖项。
  • 您可以击倒与您想要使用的包的依赖树中所需的版本一致的版本peg。
  • 如果他们发布了一个版本,但尚未将此版本发布到NPMjs,则您可以找到另一个包,或者查看它们的Github。

希望这会有所帮助:)

西德诺特:

在将此项目迁移到宿主提供商时,您还需要告诉他们,您已经在--legacy-peer-deps中强制安装了包,方法是在宿主提供商平台上为站点创建一个环境变量,或者使用.npmrc文件,其中包含以下内容:

代码语言:javascript
复制
legacy-peer-deps=true
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72887003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档