gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:27:50 26 4
gpt4 key购买 nike

  • 目标:尝试使用 Gatsby 创建一个简单的博客

  • 结果:

    • 预期结果:事情应该按照教程指南中的定义进行
    • 实际结果:在该项目中使用 npm 安装某些东西时,在步骤中出现依赖树错误,并且还会出现类似 34 ​​个漏洞(11 个中等,23 个高) 的警告消息
  • 方法:我遵循指南 available here , & 在 Task install MDX transform plugin , 出现以下错误

问题:

  1. 我如何解决这个特定的依赖树问题以及通常我如何处理 npm 中的这种(依赖树问题)错误?
  2. 与易受攻击的软件包相关的警告 - 这些警告有多重要以及应该如何处理?
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:

在尝试了 stack-overflow 站点成员给出的建议之一后,抛出了一个新错误!因此,忽略依赖树问题并跳过遗留树是行不通的,因此来自任何 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

最佳答案

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

npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1 --legacy-peer-deps

基本上这将做的是告诉 npm 您希望安装对等依赖项,发生这种情况的原因是因为您在项目中使用 React@18.2,但是您尝试安装的包使用的是较低版本的 React .因此,NPM 会向您抛出此错误。

“你不应该”通常这样做的原因是,想象在一个被标记为 vunerable 的包中有一个依赖项,但你目前安装了这个的“固定”版本。然后,您将安装可能具有漏洞的对等依赖项。

你可以运行上面的代码并且“没问题”,它想要安装较低版本的 React 没什么大不了的。

但您还应该考虑的是,您是否真的需要 React@18.2,或者您是否可以使用降级版本,因为您有多大可能使用最新版本发布中可能包含的任何功能。

这也是为什么许多开发人员在构建项目时不直接安装最新版本的 React 的原因,因为您必须依赖由独立开发人员或社区维护的包一群可爱的人,他们愿意帮助维护一个包,以使其与 Reacts 最新版本保持同步。

这些几乎是您可以做的三件主要事情:

  • 您可以安装遗留依赖项
  • 您将 React 与您要使用的包的依赖树中所需的版本内联的版本 Hook
  • 您找到另一个包,或者您查看他们的 Github,因为他们已经发布了一个版本,但尚未将此版本发布到 NPMjs

希望这有帮助:)

旁注:

将此项目迁移到托管服务提供商时,您还需要通过为托管服务提供商平台上的站点,或带有包含以下内容的 .npmrc 文件:

legacy-peer-deps=true

关于javascript - 无法在 gatsby 站点中安装和配置 MDX 转换器插件(和依赖项),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72887003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com