npx create-react-app my-project
会导致以下依赖项错误:
npx版本:8.5.0
Installing template dependencies using npm...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: react-18@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"<18.0.0" from @testing-library/react@12.1.5
npm ERR! node_modules/@testing-library/react
npm ERR! @testing-library/react@"^12.0.0" 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 start
时,会出现node-modules
中缺少web-vitals
的错误。尝试的解决方案:
- 根据上述错误消息建议,使用相同命令并加上
--force
或--legacy-peer-deps
参数不能解决问题。
- 删除node_modules
和package-lock.json
文件,然后运行npm i
也无法解决问题。更新:
最新版的
create-react-app
已经修复了这个问题。现在它可以正常创建项目了。