npm install 出现错误 - npm 错误 ERESOLVE 无法解析依赖关系树

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

在我的 React Native with TypeScript 项目中,我想安装依赖项。

要安装测试库我使用了以下命令:

npm install @testing-library/react-native @testing-library/jest-native --save-dev

但是它给了我这个错误:

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@"18.2.0" from the root project
npm error   peer react@">=16.8.0" from @testing-library/[email protected]
npm error   node_modules/@testing-library/react-native
npm error     dev @testing-library/react-native@"*" from the root project
npm error   1 more (react-native)
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.3.1" from [email protected]
npm error node_modules/react-test-renderer
npm error   peer react-test-renderer@">=16.8.0" from @testing-library/[email protected]
npm error   node_modules/@testing-library/react-native
npm error     dev @testing-library/react-native@"*" 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

-- 我也尝试过 --legacy-peer-deps 但是,npm install 不起作用,我不确定出了什么问题。

===> npm ls react-dom 的输出:

[email protected] /Users/App
└── (empty)

===> npm ls React 的输出:

[email protected] /Users/****/App
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped
├─┬ @testing-library/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ @react-native/[email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
└── [email protected]

我已经尝试过

--legacy-peer-deps
,它是暂时工作的,但是当我尝试添加 ESLint 时,它再次给我错误。

npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: @testing-library/[email protected]
npm error Found: [email protected]
javascript typescript react-native jestjs eslint
1个回答
0
投票

我找到了解决方案:

使用 Yarn 代替 npm: 如果 npm 继续出现依赖关系树解析问题,您可以切换到yarn,它通常可以更优雅地处理对等依赖关系解析:

安装纱线:

npm install -g yarn

使用 Yarn 安装依赖项:

yarn add [email protected] [email protected] @testing-library/react-native jest ts-jest @types/jest --dev

Yarn 将自动解决 npm 遇到的冲突。

© www.soinside.com 2019 - 2024. All rights reserved.