首页 > 解决方案 > react-native 链接错误“未知依赖项”

问题描述

我正在按照示例构建一个小型视频聊天:https ://www.agora.io/en/blog/how-to-build-a-react-native-video-calling-app-using-agora

我通过以下方式创建了一个新项目:npx react-native init AwesomeProject

我添加了必要的依赖项:

npm install --save react-native-agora
npm install --save react-native-router-flux
npm install --save react-native-vector-icons

依赖关系也可以在 package.json 中看到

...
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-agora": "^2.9.1-alpha.2",
    "react-native-router-flux": "^4.0.6",
    "react-native-vector-icons": "^6.6.0"
  },
...

当我通过npx react-native run-ios应用程序启动应用程序时,将在我的版本 10.2.1 (SimulatorApp-880.5 CoreSimulator-587.35)上启动

我收到以下错误:Invariant Violation: Native module cannot be null. constructor NativeEventEmitter.js

我尝试重建它npm install并且构建成功。

我的猜测是我错过了将 react 链接到 react-native-agora。我试图将其链接,react-native link react-native-agora但我收到以下错误消息:

error Unknown dependency. Make sure that the package you are trying to link is already installed in your "node_modules" and present in your "package.json" dependencies.

提前致谢。

标签: iosreactjsreact-nativenpmagora.io

解决方案


我在 npm 上遇到了类似的问题,正如Nishant评论的那样尝试删除node_modules文件夹并尝试npm installyarn install.


推荐阅读