将raect项目更新到最新的npm包时,npm install
出现错误
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-scripts@5.0.1
npm ERR! Found: typescript@5.2.2
npm ERR! node_modules/typescript
npm ERR! typescript@"^5.2.2" from the root project
npm ERR! peer typescript@">= 2.7" from fork-ts-checker-webpack-plugin@6.5.3
npm ERR! node_modules/fork-ts-checker-webpack-plugin
npm ERR! fork-ts-checker-webpack-plugin@"^6.5.0" from react-dev-utils@12.0.1
npm ERR! node_modules/react-dev-utils
npm ERR! react-dev-utils@"^12.0.1" from react-scripts@5.0.1
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"5.0.1" from the root project
npm ERR! 2 more (ts-node, tsutils)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1 || ^4" from react-scripts@5.0.1
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"5.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: typescript@4.9.5
npm ERR! node_modules/typescript
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"5.0.1" 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!
已更正npm install --force
,但随后出现警告:
npm WARN using --force Recommended protections disabled.
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: react-scripts@5.0.1
npm WARN Found: typescript@5.2.2
npm WARN node_modules/typescript
npm WARN typescript@"^5.2.2" from the root project
npm WARN 3 more (fork-ts-checker-webpack-plugin, ts-node, tsutils)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional typescript@"^3.2.1 || ^4" from react-scripts@5.0.1
npm WARN node_modules/react-scripts
npm WARN react-scripts@"5.0.1" from the root project
npm WARN
npm WARN Conflicting peer dependency: typescript@4.9.5
npm WARN node_modules/typescript
npm WARN peerOptional typescript@"^3.2.1 || ^4" from react-scripts@5.0.1
npm WARN node_modules/react-scripts
npm WARN react-scripts@"5.0.1" from the root project
added 24 packages, removed 49 packages, changed 237 packages, and audited 1596 packages in 2m
8 vulnerabilities (2 moderate, 6 high)
问题是:这正常吗?--force
是否足以解决问题,或者有没有办法最终克服这个问题?
--legacy-peer-deps
根本不合适,因为它会将一些包从所需版本回滚到旧版本
不是说这是正常的,但这就是生活。更新依赖于旧版本的软件包(如果需要)或删除它们。或者接受peerDependency之间的版本不匹配(如果它没有破坏任何东西)。
或者,切换到 pnpm 并更改依赖项版本https://pnpm.io/package_json#pnpmpeerdependencyrulesallowedversions