首页 > 解决方案 > 如何修复:TypeError:null 不是对象(评估“AgoraRtcChannelModule.prefix”)?

问题描述

每次我将 RtcEngine 导入我的应用程序 ( import RtcEngine from 'react-native-agora';) 时,我都会收到以下错误:

TypeError: null is not an object (evaluating 'AgoraRtcChannelModule.prefix')
at node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
at node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:62:36 in tryCatch
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:288:29 in invoke
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:62:36 in tryCatch
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:152:27 in invoke
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:162:18 in Promise.resolve.then$argument_0
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
at node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:62:36 in tryCatch
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:288:29 in invoke
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:62:36 in tryCatch
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:152:27 in invoke
at node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:162:18 in Promise.resolve.then$argument_0
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

注意:这是没有任何电话的。

对此的任何帮助将不胜感激。我对 react-native 和 javascript 还很陌生,所以我希望我已经提供了足够的信息。

标签: javascriptreactjsreact-nativenpmagora.io

解决方案


Agora SDK 是一个原生模块,我看到你正在尝试将它与 expo 一起使用。Expo 托管工作流不支持原生模块,您可以弹出到裸工作流或使用 react-native CLI。

更新: Expo 现在支持使用本机模块,而无需使用自定义开发客户端弹出到裸 wofklow,您可以在此处
了解有关在 Agora 中使用它们的更多信息。


推荐阅读