Javascript 不变冲突:本机模块不能为Null。仅在iOS上显示时出错

Javascript 不变冲突:本机模块不能为Null。仅在iOS上显示时出错,javascript,ios,react-native,expo,Javascript,Ios,React Native,Expo,背景 我已经开发了一个由Expo管理的React原生应用程序将近一年了,但由于当时我既没有Mac电脑也没有iPhone,所以无法在iOS上测试。 我设法买了一部iPhone8,今天我试着在上面运行这个应用程序,但没有结果 问题 我得到一个不变的冲突:当尝试运行应用程序时,本机模块不能为null。 VS代码中的错误堆栈如下所示: Invariant Violation: Native module cannot be null. - node_modules\react-native\Librar

背景 我已经开发了一个由Expo管理的React原生应用程序将近一年了,但由于当时我既没有Mac电脑也没有iPhone,所以无法在iOS上测试。 我设法买了一部iPhone8,今天我试着在上面运行这个应用程序,但没有结果

问题 我得到一个不变的冲突:当尝试运行应用程序时,本机模块不能为null。 VS代码中的错误堆栈如下所示:

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
这些截图显示了我在手机上看到的内容:

如果我尝试按照我编写的屏幕链接进行操作,而不是按照我在以下代码片段中找到的随机节点\模块依赖项进行操作:

  • 过滤器

                    <View style={styles.check}>
                         <Text style={styles.propName}>Happy hour</Text>
                     <CheckBox
                         value={selectedExtra ? true : extra3}
                         onValueChange={() => setExtra3(!extra3)}
                         tintColors={tintColors}
                         />
                     </View>
    
    
    欢乐时光
    setExtra3(!extra3)}
    tintColors={tintColors}
    />
    
  • 轮廓屏

  • navigation.navigate('yourphases')}>
    你的命令
    
    (灰色箭头和样式表导入很好。导航和其他一切在Android上都能完美工作)

    我尝试过的

    该应用程序在Android上运行完美,遇到0个问题。我尝试了
    npx react native link
    ,卸载并重新安装所有依赖项,首先在Android上构建并运行,然后在iOS上运行。 由于这是一款由世博会管理的应用程序,据我所知,我无法使用“
    cd/ios-->pod install
    ”方法

    问题

    如何让应用程序在iOS上运行,以及是什么导致了崩溃


    提前谢谢你

    我过去经常看到这个错误。当ios本机模块未正确安装时,会发生此问题。您应该为ios安装本机模块

    按照react原生项目中的下一步操作

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

    谢谢大家!

    如果您使用的是较旧的EXPO版本,请将其更新为最新版本。首先卸载它并运行
    npm安装-g expo cli

    然后清除节点模块文件夹并运行
    npm install
    再次安装节点模块。

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

    嘿,正如我在帖子中指定的,我不能这样做,因为它是一个世博会托管应用程序。哦,对不起。我错过了。太麻烦了
    cd ios
    rm -rf Pods Podfile.lock
    pod install
    yarn ios