我试图添加一个博客到我的盖茨比网站,其中涉及增加MDX的支持。当我试图通过运行以下命令安装MDX插件时,我会得到以下错误:
命令 npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1
误差
E:\Dev\Web\dantcho.com>npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: dantcho@1.0.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR! react@"^18.2.0" from the root project
npm ERR! peer react@"^16.9.0 || ^17.0.0 || ^18.0.0" from gatsby-plugin-mdx@3.16.1
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.16.1
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 C:\Users\dantc\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dantc\AppData\Local\npm-cache\_logs\2022-06-18T01_43_31_526Z-debug-0.log附加信息:
package.json
{
"name": "dantcho",
"version": "1.0.0",
"private": true,
"description": "Dantcho",
"author": "Yordan Hristov (Dantcho)",
"keywords": [
"gatsby"
],
"scripts": {
"develop": "gatsby develop",
"start": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean"
},
"dependencies": {
"@fontsource/rubik": "^4.5.10",
"babel-plugin-styled-components": "^2.0.7",
"framer-motion": "^6.3.11",
"gatsby": "^4.16.0",
"gatsby-plugin-image": "^2.16.1",
"gatsby-plugin-manifest": "^4.16.0",
"gatsby-plugin-react-helmet": "^5.16.0",
"gatsby-plugin-sharp": "^4.16.1",
"gatsby-plugin-styled-components": "^5.16.0",
"gatsby-remark-images": "^6.16.0",
"gatsby-source-filesystem": "^4.16.0",
"gatsby-transformer-remark": "^5.16.0",
"gatsby-transformer-sharp": "^4.16.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"styled-components": "^5.3.5"
}
}节点版本 16.14.0
NPM版本 8.6.0
OS Windows 10
更新
我试图创建一个全新的盖茨比项目,并安装我需要的软件包。这样,我就可以消除不同软件包的旧版本或错误版本的任何可能性。(这是行不通的)我开始有一个类似的问题,与许多其他软件包。
解决方案(至少对我而言)
转而使用雅恩。
发布于 2022-06-21 13:49:59
我试过这个命令,它对我来说很好。
npm config set legacy-peer-deps true
npm install --force发布于 2022-06-27 22:19:01
在尝试安装时,我也犯了同样的错误。项目中的React (18.2.0)和这些插件应该使用的.之间的依赖冲突。
因此,解决方案非常简单:只需通过编辑package.json文件来降低您的react。
而不是这样:
"dependencies": {
...
"react": "^18.2.0",
"react-dom": "^18.2.0",
...
},更改为早期版本,如16.14.0:
"dependencies": {
...
"react": "^16.14.0",
"react-dom": "^16.14.0",
...
},然后,保存文件。之后,在终端中运行以下代码以删除安装在项目中的当前模块。
rm node_modules
最后,只需通过运行以下命令重新安装node_modules包:
npm install现在,您可以重试并安装您的mdx插件:
npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1希望它对你有用!
(我不太确定你的反应是否会引起一些副作用问题,但这种方式对我来说是有效的。如果有人能澄清这件事,我会很感激的)
发布于 2022-06-18 08:29:46
我试过这个命令npm install gatsby-plugin-mdx @mdx-js/mdx@v1 @mdx-js/react@v1,它对我很好
package.json
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"gatsby-plugin-mdx": "^3.16.1"
}
}我认为问题在文件夹路径中。
https://stackoverflow.com/questions/72666146
复制相似问题