问题描述
我正在使用react native创建一个简单的移动应用程序。在添加redux之前,该项目在模拟器上运行良好。我正在使用redux登录和注销;它实际上只是一个reducer和action文件,用于在登录时将authedUser设置为具有注册用户名的用户,而在注销时将其设置为null。如果我在网络浏览器上运行它,则可以正常运行,但不能在ios / android模拟器上运行。通过react-native run-android
在模拟器上运行时,出现上述错误。当通过expo运行它时,我得到:不变违规:“ main”尚未注册。
here is a screenshot of the error
完全迷路了有什么建议吗?
package.json内容:
{
"main": "index.js","scripts": {
"android": "react-native run-android","ios": "react-native run-ios","web": "expo start --web","start": "react-native start","test": "jest"
},"dependencies": {
"@react-native-community/async-storage": "^1.11.0","@react-native-community/masked-view": "0.1.10","@react-navigation/bottom-tabs": "^5.7.3","@react-navigation/native": "^5.7.2","@reduxjs/toolkit": "^1.4.0","expo": "~38.0.1","expo-updates": "~0.2.10","react": "~16.11.0","react-dom": "^16.13.1","react-native": "~0.62.2","react-native-elements": "^2.0.4","react-native-gesture-handler": "~1.6.0","react-native-qrcode-svg": "^6.0.6","react-native-reanimated": "~1.9.0","react-native-safe-area-context": "~3.0.7","react-native-screens": "~2.9.0","react-native-svg": "^12.1.0","react-native-unimodules": "~0.10.1","react-native-web": "~0.11.7","react-redux": "^7.2.1","redux": "^4.0.5"
},"devDependencies": {
"@babel/core": "~7.9.0","babel-jest": "~25.2.6","jest": "~25.2.6","react-test-renderer": "~16.11.0"
},"jest": {
"preset": "react-native"
},"private": true
}
解决方法
当您在带有调试模式的模拟器中运行应用程序时,由于调试器是chrome devtools,因此它将知道文档的实例,并且不会产生任何错误。基本上,您正在使用本机应用程序中webapp所使用的npm模块。您能否列出package.json文件的内容。