背景我开发一个由 Expo 管理的 React Native 应用程序已经快一年了,但由于当时我既没有 Mac 也没有 iPhone,所以无法在 iOS 上测试它。
我设法购买了 iPhone 8,今天我尝试在其上运行该应用程序,但没有结果。
Problem我遇到不变违规:尝试运行应用程序时本机模块不能为空。
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:
![First one](https://i.stack.imgur.com/8BDSc.jpg)
如果我尝试点击我编码的屏幕的链接,而不是随机的 node_modules 依赖项,我会看到这些代码片段:
-
Filters
<View style={styles.check}>
<Text style={styles.propName}>Happy hour</Text>
<CheckBox
value={selectedExtra ? true : extra3}
onValueChange={() => setExtra3(!extra3)}
tintColors={tintColors}
/>
</View>
-
个人资料屏幕
<TouchableOpacity style={styles.listItem} onPress={() => navigation.navigate('yourPurchases')}>
<Text style={styles.listText}>Your orders</Text>
<View style={styles.greyArrow}>
<GreyArrow />
</View>
</TouchableOpacity>
(灰色箭头和样式表导入就很好。导航和其他一切都在 Android 上完美运行)。
我尝试过的
该应用程序在 Android 上完美运行,遇到 0 个问题。我试过了npx react-native link
,卸载并重新安装所有依赖项,首先在 Android 上构建并运行,然后在 iOS 上构建和运行。
由于这是一个世博会管理的应用程序,据我所知我无法使用“cd /ios --> pod install
“ 方法。
Question
如何让应用程序在 iOS 上运行以及导致崩溃的原因是什么?
预先非常感谢!