首页 > 解决方案 > ReferenceError:找不到变量:文档

问题描述

我正在使用 react native 创建一个简单的移动应用程序。该项目在模拟器上运行良好,直到我添加了 redux。我正在使用 redux 进行登录和注销;它实际上只是一个减速器和操作文件,用于在登录时使用注册用户名设置 authedUser,并在注销时设置为 null。如果我在网络浏览器上运行它,它可以正常工作,但不能在 ios/android 模拟器上运行。通过在模拟器上运行时react-native run-android出现上述错误。通过 expo 运行它时,我得到: Invariant Violation: “main” has not been registered。 这是 完全丢失的错误的屏幕截图。有什么建议么?

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
}

标签: reactjsreact-nativereduxnative

解决方案


当您在调试模式下在模拟器中运行您的应用程序时,由于调试器是 chrome devtools,它会知道文档的实例并且不会产生任何错误。基本上,您使用的是 webapp 在您的 react native 应用程序中使用的一些 npm 模块。你能列出你的 package.json 文件的内容吗?


推荐阅读