不变违规:`new NativeEventEmitter()` 需要一个非空参数。,js 引擎:hermes
// No problem at all with this code
import {View, Text} from 'react-native'
const App = () => {
return (
<View>
<Text>
Test
</Text>
</View>
)
}
export default App
OUTPUT: LOG Running "Chat" with {"rootTag":161,"initialProps":{}}
info Reloading app...
BUNDLE ./index.js
********************************************
// but as soon as I import
import {View, Text} from 'react-native'
import {Voximplant} from 'react-native-voximplant'; <--
const client = Voximplant.getInstance(); <--
const App = () => {
return (
<View>
<Text>
Test
</Text>
</View>
)
}
export default App
// I get the following.
OUTPUT: LOG Running "Chat" with {"rootTag":171,"initialProps":{}}
ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., js engine: hermes
我尝试了 GitHub 和 stack overflow 上的所有最新答案,但都不起作用。现在我不知道该怎么办。由于这个问题,我无法使用 Voximplant。
{ "name": "Chat", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest" }, "dependencies": { "react": "18.2.0", "react-native": "0.71.5", "react-native-voximplant": "^1.36.0" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": “^7.20.0”, “@react-native-community/eslint-config”:“^3.2.0”, “@tsconfig/react-native”:“^2.0.2”, “@types/jest”:“^29.2.1”, “@types/react”:“^18.0.24”, “@types/react-test-renderer”:“^18.0.0”, “babel-jest”:“^29.2.1”, “eslint”:“^8.19.0”, “jest”:“^29.2.1”, “metro-react-native-babel-preset”:“0.73.9”, “prettier”:“^2.4.1”, “react-test-renderer”:“18.2.0”, “typescript”:“4.8.4” }, “jest”: { "preset": "react-native" }
目前在 MacBook Pro M2 上运行,操作系统:macOs Ventura 版本 13.3
为了确保万无一失,在添加新模块后,您是否在 ios 文件夹中运行了
pod install
?
当您安装新模块但没有为 iOS 开发生成 pod 时,这看起来像是一个错误。
步骤:
-
导航到 react-native 项目中的 ios 文件夹。
-
从终端运行
pod install
。 -
在 Xcode 上,使用快捷键
cmd+shift+k
清理您的项目。(专业提示:您可以删除 ~/Library/Developer/XCode/DerivedData 中的 Derived Data 文件夹,成功构建应用程序后它将再次生成)。 -
构建您的应用程序(
cmd+r
);