react-native - 使用 React Native 导入任何依赖项时出错
问题描述
初始化 React Native 项目后,如果我安装并导入任何其他依赖项,运行“react-native run-ios”后将显示此错误消息:
例如:我运行“react-native init RNProject”来创建简单的反应原生项目。之后我通过:“npm install --save-dev react-navigation”安装react-navigation,然后我通过“import {createStackNavigator} from 'react-navigation'导入createStackNavigator;” 在 App.js 中,什么也不做。在运行“react-native run-ios”并得到上面的错误之后。从'react-navigation'中删除“import {createStackNavigator};” 将导致应用程序正常运行。
我试过“rm node_modules/react-native/local-cli/core/fixtures/files/package.json”或“rm ./node_modules/react-native/local-cli/core/fixtures/files/package.json ”但是终端显示“没有这样的文件或目录”。
我的环境
| software | version
| ---------------- | -------
| react-navigation | 2.6.2
| react-native | 0.56.0
| node | 8.11.3
| npm | 5.3.0
| MacOS | 10.13.5
解决方案
Problem:
Because you used --save-dev
in install cmd which means it will be installed as devDependencies
in your project.
Solution:
Try just installing with this npm install --save react-navigation
which will install it as dependencies
;
Look at you package.json if you find react-navigation
this in dependencies
section and still find same problem try deleting node_modules
and npm i
推荐阅读
- java - Swagger for java - 必填字段阻止执行
- c# - Ball Breaker Game - 在某些反弹后,球被卡在桨上 - Unity
- postgresql - Spring Data JPA 并转换为 Postgres 自定义域
- imodeljs - IModelReadRpcInterface.openForRead() 不可用
- r - 使用 MASS 中的 boxcox 时,未为此 S4 类定义 $ 运算符
- git - 如何使用 git diff 获取每个目录中的文件更改总数
- python - 如何使用 Python 将文件连接并推送到 informatica
- r - 为日期时间 X 轴设置小中断,ggplot
- video-streaming - 将 EME 与 ClearKey 一起使用时的视频解密过程
- c++ - 命令行参数添加一个额外的参数