使用 npm 安装模板依赖项...npm 错误代码 ERESOLVE

问题描述 投票:0回答:1

我正在努力做

npx create-react-app calc-app

一切都已正确安装,但出现了

Installing template dependencies using npm...
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"^13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error C:\Users\ariana\AppData\Local\npm-cache\_logs\2024-12-18T14_26_32_953Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\ariana\AppData\Local\npm-cache\_logs\2024-12-18T14_26_32_953Z-debug-0.log
`npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0` failed

所以我尝试运行“npm install”

这就是消息

npm error code ENOENT
npm error syscall open
npm error path C:\Users\ariana\Documents\Cursos\React\package.json
npm error errno -4058
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Users\ariana\Documents\Cursos\React\package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: C:\Users\ariana\AppData\Local\npm-cache\_logs\2024-12-18T14_30_41_989Z-debug-0.log

不知道还能做什么

reactjs npm
1个回答
0
投票

其中一个依赖项(

@testing-library/[email protected]
期望
react@~18.0.0
)与React版本(
[email protected]
)不兼容,是导致此问题的原因。修复方法如下:

应使用

--legacy-peer-deps
flag:要解决依赖关系解析问题,请使用此标志再次运行
npx create-react-app
命令:

npx create-react-app calc-app --use-npm --legacy-peer-deps
© www.soinside.com 2019 - 2024. All rights reserved.