如何解决 gatsby js 中的依赖错误?

Lee*_*seo 2 reactjs gatsby

我正在关注 Gatsbyjs 教程。( https://www.gatsbyjs.com/docs/tutorial/part-four/ ) 链接在这里。

我在窗口终端中输入命令,

gatsby new tutorial-part-four https://github.com/gatsbyjs/gatsby-starter-hello-world
cd tutorial-part-four

npm install gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion @emotion/react
Run Code Online (Sandbox Code Playgroud)

但是这些消息发生了错误,

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: gatsby-starter-hello-world@0.1.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!   peer react@"^16.9.0 || ^17.0.0" from gatsby-plugin-typography@3.0.0
npm ERR!   node_modules/gatsby-plugin-typography
npm ERR!     gatsby-plugin-typography@"*" from the root project
npm ERR!   2 more (gatsby, react-dom)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.0 || ^15.0.0 || ^16.0.0" from react-typography@0.16.19
npm ERR! node_modules/react-typography
npm ERR!   peer react-typography@"^0.16.1 || ^1.0.0-alpha.0" from gatsby-plugin-typography@3.0.0
npm ERR!   node_modules/gatsby-plugin-typography
npm ERR!     gatsby-plugin-typography@"*" 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\pc\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\pc\AppData\Local\npm-cache\_logs\2021-03-13T09_43_09_116Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我想知道如何解决这些错误?

小智 7

react-typography 尚未准备好反应 17,因此您必须将反应降级到版本 16 才能使用它。

编辑package.json并查找:

"dependencies": {
  ...
  "react": "^17.0.1",
  "react-dom": "^17.0.1",
  ...
},
Run Code Online (Sandbox Code Playgroud)

将版本号更改为 16.14.0

"dependencies": {
  ...
  "react": "^16.14.0",
  "react-dom": "^16.14.0",
  ...
},
Run Code Online (Sandbox Code Playgroud)

保存它,然后从中删除所有文件 node_modules/

rm -Rf node_modules

最后,只需使用以下命令重新安装所有内容:

npm install

继续执行您的命令...

npm install gatsby-plugin-typography typography react-typography typography-theme-kirkham gatsby-plugin-emotion @emotion/react