javascript - 库未导入
问题描述
我正在尝试在我的 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
当我尝试导入其他一些库时,它也给了我同样的错误。以前,当我在旧项目中导入导航库时,它工作正常,但现在它给了我这个错误。
好心,有人告诉我为什么会出现这个错误。以及如何解决问题以及如何避免将来出现同样的问题。
如果有人帮助我,我将非常感激,因为我是开发的相对初学者并且不知道这个错误的逻辑。
解决方案
你有依赖冲突!这意味着您有一个不正确且可能损坏的依赖项。先试试这个:
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
文件中安装依赖项。
推荐阅读
- c# - 这个 50/51 问题出了什么问题?
- php - 无法连接到主机端口 88:连接被拒绝
- java - 无法从 application.yml 加载属性未绑定
- python - 如何在 Django 中以单一形式上传多个文件?
- javascript - 关于Axios的使用
- amazon-web-services - 在 puresec 的函数屏蔽上检测到空的 aws lambda 子进程执行
- wcf - 收到错误“合同不匹配 - 发送方和接收方之间的操作不匹配”
- c++ - 非类型模板参数:从 bool 到 int 的隐式转换有效,但从 double 到 int 无效。这是为什么?
- nativescript - 如何:使用 Webpack 自定义 CSS 文件?(本机脚本)
- php - Laravel:OVH 托管 SQLSTATE [HY000] [2002] 连接超时