首页 > 解决方案 > 每次我安装新的 react-app 时依赖关系树中的错误

问题描述

每次创建 React 应用程序时都会出现错误,这已经有一段时间了。

我尝试删除所有节点/npm 版本,并使用最新的节点 LTS 重新安装一个干净的版本,但是,我仍然收到以下错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: type-fest@0.21.3
npm ERR! node_modules/type-fest
npm ERR!   type-fest@"^0.21.3" from ansi-escapes@4.3.2
npm ERR!   node_modules/ansi-escapes
npm ERR!     ansi-escapes@"^4.2.1" from @jest/core@26.6.3
npm ERR!     node_modules/@jest/core
npm ERR!       @jest/core@"^26.6.0" from jest@26.6.0
npm ERR!       node_modules/jest
npm ERR!         peer jest@"^26.0.0" from jest-watch-typeahead@0.6.1
npm ERR!         node_modules/jest-watch-typeahead
npm ERR!         1 more (react-scripts)
npm ERR!       1 more (jest-cli)
npm ERR!     ansi-escapes@"^4.3.1" from jest-watch-typeahead@0.6.1
npm ERR!     node_modules/jest-watch-typeahead
npm ERR!       jest-watch-typeahead@"0.6.1" from react-scripts@4.0.3
npm ERR!       node_modules/react-scripts
npm ERR!         react-scripts@"^4.0.3" from the root project
npm ERR!     2 more (jest-watcher, terminal-link)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional type-fest@"^0.13.1" from @pmmmwh/react-refresh-webpack-plugin@0.4.3
npm ERR! node_modules/@pmmmwh/react-refresh-webpack-plugin
npm ERR!   @pmmmwh/react-refresh-webpack-plugin@"0.4.3" from react-scripts@4.0.3
npm ERR!   node_modules/react-scripts
npm ERR!     react-scripts@"^4.0.3" 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 /Users/johnnys/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/johnnys/.npm/_logs/2021-07-10T18_33_36_275Z-debug.log

标签: node.jsreactjsnpm

解决方案


您从有关此问题的类似帖子中收到相同类型的错误npm audit fix --force 永远无法避免漏洞

GitHub create-react-app repo 中还有一张已关闭的票证。这是答案之一:

你好,

确保这件事

您的依赖项(包括 NodeJS/npm/npx/yarn)是最新的,确保未全局安装 CRA 按照 https://create-react-app.dev/docs/getting-started/指南开始

您可能需要继续将依赖项更新到最新版本并等待最新版本修复此问题。


推荐阅读