首页 > 解决方案 > 库未导入

问题描述

我正在尝试在我的 react native 项目中导入 react-navigation 库。但它给了我这个错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: IbexCrypto@0.0.1
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR!   peer react@"*" from @react-navigation/stack@5.14.3
npm ERR!   node_modules/@react-navigation/stack
npm ERR!     @react-navigation/stack@"*" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.0" from @react-native-community/masked-view@0.1.10
npm ERR! node_modules/@react-native-community/masked-view
npm ERR!   peer @react-native-community/masked-view@">= 0.1.0" from @react-navigation/stack@5.14.3
npm ERR!   node_modules/@react-navigation/stack
npm ERR!     @react-navigation/stack@"*" 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 C:\Users\me\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Local\npm-cache\_logs\2021-03-17T15_24_47_867Z-debug.log

当我尝试导入其他一些库时,它也给了我同样的错误。以前,当我在旧项目中导入导航库时,它工作正常,但现在它给了我这个错误。

好心,有人告诉我为什么会出现这个错误。以及如何解决问题以及如何避免将来出现同样的问题。

如果有人帮助我,我将非常感激,因为我是开发的相对初学者并且不知道这个错误的逻辑。

标签: javascriptreact-nativenpmreact-navigationlibraries

解决方案


你有依赖冲突!这意味着您有一个不正确可能损坏的依赖项。先试试这个:

rm -rf node_modules/
npm install

此命令删除node_modules文件夹,然后安装您在您的package.json

如果它不起作用,请尝试npm install使用命令--force--legacy-peer-deps.

在你的情况下: npm install @react-navigation/native --force

或者:npm install @react-navigation/native --legacy-peer-deps

命令说明:

--force: 强制npm install安装要安装的依赖项。

-legacy-peer-deps: --legacy-peer-deps: 安装时忽略所有 peerDependencies。

这些命令在某些情况下是必需的,但作为标准npm install应该足以从您的package.json文件中安装依赖项。


推荐阅读