简体   繁体   English

不变违规:Native Module 不能是 Null。 错误仅出现在 iOS

[英]Invariant Violation: Native Module cannot be Null. Error only showing up on iOS

Background I've been developing a React Native app managed by Expo for almost a year now, but was unable to test it on iOS given I didn't have neither a Mac nor an iPhone at my disposal back then.背景我一直在开发由 Expo 管理的 React Native 应用程序将近一年了,但由于当时我既没有 Mac 也没有 iPhone 可供我使用,所以无法在 iOS 上对其进行测试。 I managed to buy an iPhone 8 and today I tried running the app on it to no result.我设法购买了 iPhone 8,今天我尝试在其上运行该应用程序,但没有结果。

Problem I get an Invariant violation: Native module cannot be null when trying to run the app.问题我得到一个不变的违规:尝试运行应用程序时,本机模块不能是 null。 The error stack reads as follows in VS Code:错误堆栈在 VS Code 中如下所示:

Invariant Violation: Native module cannot be null.
- node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
- node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
- node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
- node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
- node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
- node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException
- node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
- node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:9:32 in ErrorUtils.setGlobalHandler$argument_0
- node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:293:29 in invoke
- node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
- node_modules\regenerator-runtime\runtime.js:154:27 in invoke
- node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
- node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

And these screenshots show what I get on my phone:这些屏幕截图显示了我在手机上得到的信息: 第一

第二

第三

If I try and follow the links to the screens I've coded, not the random node_modules dependencies I land at these snippets of code:如果我尝试按照我编写的屏幕的链接,而不是我在这些代码片段中找到的随机 node_modules 依赖项:

  1. Filters过滤器

     <View style={styles.check}> <Text style={styles.propName}>Happy hour</Text> <CheckBox value={selectedExtra? true: extra3} onValueChange={() => setExtra3(!extra3)} tintColors={tintColors} /> </View>
  2. Profile Screen配置文件屏幕

        <TouchableOpacity style={styles.listItem} onPress={() => navigation.navigate('yourPurchases')}>
            <Text style={styles.listText}>Your orders</Text>
            <View style={styles.greyArrow}>
              <GreyArrow />
            </View>
          </TouchableOpacity>

(Grey Arrow and Stylesheet imports are just fine. Navigation and everything else works perfectly on Android). (灰色箭头和样式表导入很好。导航和其他一切都可以在 Android 上完美运行)。

What I've tried我试过的

The application runs perfectly on Android, running into 0 issues.该应用程序在 Android 上完美运行,遇到 0 个问题。 I've tried npx react-native link , uninstalling and reinstalling all dependencies, building and running first on Android and then on iOS.我试过npx react-native link ,卸载并重新安装所有依赖项,首先在 Android 上构建和运行,然后在 iOS 上运行。 As this is an expo managed app, as far as I know I can't use the " cd /ios --> pod install " method.由于这是一个 expo 托管应用程序,据我所知,我不能使用“ cd /ios --> pod install ”方法。

Question问题

How can I get the app to run on iOS and what is generating the crashes?我怎样才能让应用程序在 iOS 上运行,是什么导致了崩溃?

Thanks a whole lot in advance!提前非常感谢!

It seems that you added a library which has a native iOS-part and is not part of Expo.您似乎添加了一个具有本机 iOS 部分的库,而不是 Expo 的一部分。 You should check your package.json and for each library check on Github if there is an iOS-Folder.如果有 iOS 文件夹,您应该检查 package.json 和 Github 上的每个库检查。 If this library is not mentionioning anything about Expo and Expo does not show it either on their website for being compatible with managed project, it is probably the reason and you need to find the alternative for that or eject.如果这个库没有提到任何关于 Expo 和 Expo 的内容也没有在他们的网站上显示它与托管项目兼容,这可能是原因,你需要找到替代方案或弹出。

I often saw this error in the past.我过去经常看到这个错误。 This problem occurs when ios native module is not installed properly.当 ios 原生模块未正确安装时会出现此问题。 You should install native module for ios.您应该为 ios 安装本机模块。

Follow the next step in your react-native project按照 react-native 项目的下一步

cd ios
rm -rf Pods Podfile.lock
pod install
yarn ios

Thank you!谢谢!

If your using older EXPO version then update it to latest version.如果您使用较旧的 EXPO 版本,请将其更新到最新版本。 First uninstall it and run npm install -g expo-cli .首先卸载它并运行npm install -g expo-cli Then clear your node modules folder and run npm install to install node modules again.然后清除您的节点模块文件夹并运行npm install再次安装节点模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行测试时出现“不变违规:本机模块不能为空”。 - Getting ''Invariant Violation: Native module cannot be null.'' when I run the test 开玩笑,反应本机和异步存储:不变违规:本机模块不能是 null - Jest, React native and async-storage : Invariant Violation: Native module cannot be null 反应本机不变违反错误 - React native invariant violation error React Native - Xcode 12.1 &amp; iOS 14.0.1 不变违规:模块 AppRegistry 不是注册的可调用模块(调用 runApplication) - React Native - Xcode 12.1 & iOS 14.0.1 Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication) 错误:不变违规:您的 Javascript 代码试图访问不存在的本机模块 - Error: Invariant Violation: Your Javascript code tried to access a native module that doesn't exist 错误不变违规:您的 JavaScript 代码试图访问不存在的本机模块 - ERROR Invariant Violation: Your JavaScript code tried to access a native module that doesn't exist 本机模块不能是 null (ios) - Expo - Native Module cannot be null (ios) - Expo 反应本机错误-违反常态:元素类型无效 - React Native Error - Invariant Violation: Element type is invalid React Native:不变违规:超过最大更新深度错误 - React Native: Invariant Violation: Maximum update depth exceeded error ReactJS错误:不变违反 - ReactJS error: Invariant violation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM