React Native“不变违规:模块AppRegistry不是已注册的可调用模块(调用runApplication)”

sta*_*416 8 javascript android reactjs react-native react-navigation

还有许多其他具有相同标题的帖子,但其中大多数已经过时,并且答案对我不起作用。以下是我尝试过但失败的一些修复:

  • “反应本机启动--重置缓存”
  • “npm开始--重置缓存”
  • “npm 运行 android --reset-cache”
  • “cd android -> gradlew clean -> cd..”
  • 删除并重新安装node_modules文件夹
  • 在更新react-native并执行/npm审核修复之前和之后删除并重新安装node_modules文件夹。据说有0个漏洞
  • 纱线安装和纱线升级

当我尝试运行它时,即使重新启动计算机后也会出现此问题。我使用npm run android来启动应用程序。我注意到,在它停止工作的时候,我不小心向项目中添加了一些打字稿文件,而没有任何其他包。我已经删除了它们,但这有可能是造成这种情况的原因吗?我不认为它是条目文件路径的问题,因为错误状态如下所述。

有谁有其他想法如何解决它?如果需要更多代码片段,请告诉我。如有任何进一步的问题或建议,我们将不胜感激

我的 getJSMainModuleName() 返回的“index”应该是正确的,因为这在过去的项目中工作过,这让我相信它可能不是像错误所说的那样不正确的条目文件路径。

这是我执行“npm run android”时来自 Metro 的完整控制台输出。我不认为循环或引用错误导致了不变性违规。

 BUNDLE  ./index.js

 WARN  Require cycle: src\component\FeedList.js -> src\component\FeedCell.js -> src\component\TagDetail.js -> src\component\FeedList.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 ERROR  ReferenceError: Can't find variable: i
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
Run Code Online (Sandbox Code Playgroud)

当我重新加载应用程序时,我收到相同的错误,但有 4 个相同的不变违规,而不是 2 个。(请注意这一点,以防其相关)

以下是我的项目中选定的文件

索引.js

 BUNDLE  ./index.js

 WARN  Require cycle: src\component\FeedList.js -> src\component\FeedCell.js -> src\component\TagDetail.js -> src\component\FeedList.js

Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
 ERROR  ReferenceError: Can't find variable: i
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "name": "TestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.11.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/viewpager": "^4.0.0",
    "aws-sdk": "^2.693.0",
    "lodash": "^4.17.15",
    "lodash.debounce": "^4.0.8",
    "react": "16.13.1",
    "react-native": "^0.64.1",
    "react-native-deprecated-custom-components": "^0.0.0",
    "react-native-gesture-handler": "^1.10.0",
    "react-native-image-crop-picker": "^0.31.1",
    "react-native-image-picker": "^2.3.1",
    "react-native-keyboard-spacer": "^0.4.1",
    "react-native-material-menu": "^1.2.0",
    "react-native-navbar": "^2.1.0",
    "react-native-parallax-scroll-view": "^0.21.3",
    "react-native-photo-view": "^1.5.2",
    "react-native-safe-area-context": "^3.0.2",
    "react-native-screens": "^2.8.0",
    "react-native-scrollable-tab-view": "^1.0.0",
    "react-native-swiper": "^1.6.0-rc.1",
    "react-native-tab-navigator": "^0.3.4",
    "react-native-text-ticker": "^1.5.0",
    "react-native-vector-icons": "^8.1.0",
    "react-native-vertical-view-pager": "^0.1.1",
    "react-native-video": "^4.4.5",
    "react-native-view-pager": "^0.2.3",
    "react-navigation": "^4.3.9",
    "react-navigation-stack": "^2.6.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "styled-components": "^5.1.1"
  },
  "devDependencies": {
    "@babel/core": "^7.10.2",
    "@babel/runtime": "^7.10.2",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^26.0.1",
    "eslint": "^7.2.0",
    "jest": "^26.0.1",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "16.13.1"
  },
  "jest": {
    "preset": "react-native"
  }
}


Run Code Online (Sandbox Code Playgroud)

应用程序.json

{
  "name": "TestApp",
  "displayName": "TestApp"
}
Run Code Online (Sandbox Code Playgroud)

kum*_*292 -1

如果循环位于您自己的代码中,则必须将一些导出提取到第三个模块/文件中,然后将代码导入到先前形成循环的两个模块中。 这可能有帮助