不变违规:本机模块不能为空.错误仅显示在 iOS 上 [英] Invariant Violation: Native Module cannot be Null. Error only showing up on iOS

查看:16
本文介绍了不变违规:本机模块不能为空.错误仅显示在 iOS 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景近一年来,我一直在开发由 Expo 管理的 React Native 应用程序,但由于当时我既没有 Mac 也没有 iPhone,所以无法在 iOS 上对其进行测试.我设法购买了一部 iPhone 8,今天我尝试在其上运行该应用程序,但没有结果.

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. I managed to buy an iPhone 8 and today I tried running the app on it to no result.

问题我得到一个不变的违规:尝试运行应用程序时,本机模块不能为空.错误堆栈在 VS Code 中如下所示:

Problem I get an Invariant violation: Native module cannot be null when trying to run the app. The error stack reads as follows in VS Code:

Invariant Violation: Native module cannot be null.
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:148:8 in registerError
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:59:8 in errorImpl
- node_modules
eact-nativeLibrariesLogBoxLogBox.js:33:4 in console.error
- node_modulesexpouildenvironment
eact-native-logs.fx.js:27:4 in error
- node_modules
eact-nativeLibrariesCoreExceptionsManager.js:104:6 in reportException
- node_modules
eact-nativeLibrariesCoreExceptionsManager.js:171:19 in handleException
- node_modules
eact-nativeLibrariesCoresetUpErrorHandling.js:24:6 in handleError
- node_modulesexpo-error-recoveryuildErrorRecovery.fx.js:9:32 in ErrorUtils.setGlobalHandler$argument_0
- node_modules
egenerator-runtime
untime.js:63:36 in tryCatch
- node_modules
egenerator-runtime
untime.js:293:29 in invoke
- node_modules
egenerator-runtime
untime.js:63:36 in tryCatch
- node_modules
egenerator-runtime
untime.js:154:27 in invoke
- node_modules
egenerator-runtime
untime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules
eact-native
ode_modulespromisesetimmediatecore.js:37:13 in tryCallOne
- node_modules
eact-native
ode_modulespromisesetimmediatecore.js:123:24 in setImmediate$argument_0
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:130:14 in _callTimer
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:181:14 in _callImmediatesPass
- node_modules
eact-nativeLibrariesCoreTimersJSTimers.js:441:30 in callImmediates
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:387:6 in __callImmediates
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:135:6 in __guard$argument_0
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.js:364:10 in __guard
- node_modules
eact-nativeLibrariesBatchedBridgeMessageQueue.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:

如果我尝试按照我编写的屏幕的链接,而不是我在这些代码片段中找到的随机 node_modules 依赖项:

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:

  1. 过滤器

                <View style={styles.check}>
                     <Text style={styles.propName}>Happy hour</Text>
                 <CheckBox
                     value={selectedExtra ? true : extra3}
                     onValueChange={() => setExtra3(!extra3)}
                     tintColors={tintColors}
                     />
                 </View>

  • 个人资料屏幕

  • Profile Screen

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

    (灰色箭头和样式表导入很好.导航和其他一切都可以在 Android 上完美运行).

    (Grey Arrow and Stylesheet imports are just fine. Navigation and everything else works perfectly on Android).

    我的尝试

    应用程序在 Android 上完美运行,遇到 0 个问题.我试过 npx react-native link,卸载并重新安装所有依赖项,首先在 Android 上构建和运行,然后在 iOS 上运行.由于这是一个世博会管理的应用程序,据我所知,我不能使用cd/ios -->吊舱安装"方法.

    The application runs perfectly on Android, running into 0 issues. I've tried npx react-native link, uninstalling and reinstalling all dependencies, building and running first on Android and then on iOS. As this is an expo managed app, as far as I know I can't use the "cd /ios --> pod install" method.

    问题

    如何让应用在 iOS 上运行以及导致崩溃的原因是什么?

    How can I get the app to run on iOS and what is generating the crashes?

    提前非常感谢!

    推荐答案

    您似乎添加了一个具有本机 iOS 部分且不属于 Expo 的库.如果有 iOS 文件夹,您应该检查您的 package.json 并检查 Github 上的每个库.如果这个库没有提到任何关于 Expo 的内容,并且 Expo 也没有在他们的网站上显示它与托管项目兼容,这可能是原因,您需要找到替代方案或弹出.

    It seems that you added a library which has a native iOS-part and is not part of Expo. You should check your package.json and for each library check on Github if there is an iOS-Folder. 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.

    这篇关于不变违规:本机模块不能为空.错误仅显示在 iOS 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆