javascript - react 原生 "Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)"

标签 javascript android reactjs react-native react-navigation

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

  • "react-native start --reset-cache"
  • "npm start -- --reset-cache"
  • "npm run android --reset-cache"
  • “cd android -> gradlew clean -> cd..”
  • 删除并重新安装 node_modules 文件夹
  • 在更新 react-native 和执行/npm 审计修复之前和之后删除并重新安装 node_modules 文件夹。它说有 0 个漏洞
  • yarn 安装和 yarn 升级

  • 当我尝试运行它时会发生此问题,即使在重新启动计算机后也是如此。我用 npm 运行安卓 启动应用程序。我注意到,在它停止工作的时候,我不小心在项目中添加了一些 typescript 文件,而没有任何额外的包。我已经删除了它们,但这可能是导致它的原因吗?由于下面提到的原因,我认为错误状态不是入口文件路径的问题。
    有没有人有任何其他想法如何解决它?如果需要更多代码 fragment ,请告诉我。任何可能引领方向的进一步问题或建议表示赞赏
    我的 getJSMainModuleName() 返回“索引”,它应该是正确的,因为过去在这个项目上工作过,这让我相信它可能不是错误的入口文件路径,就像错误所说的那样。
    这是我执行“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.
    
    当我重新加载应用程序时,我得到了同样的错误,但有 4 个相同的不变违规而不是 2 个。(注意这一点是相关的)
    以下是从我的项目中选择的文件
    index.js
    import React, { Component } from 'react';
    import { Provider } from 'react-redux';
    import { AppRegistry} from 'react-native';
    import { createStackNavigator} from "react-navigation-stack";
    //import { StackNavigator } from 'react-navigation';
    import { createAppContainer } from 'react-navigation';
    import App from './src/App';
    import configureStore from './src/store/index';
    import TagDetail from './src/component/TagDetail';
    import FeedDetail from './src/component/FeedDetail';
    import UserDetail from './src/component/UserDetail';
    import SettingsPage from './src/SettingsPage';
    import About from './src/About';
    
    
    import {name as appName} from './app.json';
    
    const store = configureStore();
    
    
    const AppNavigator = createStackNavigator({
      Home: {
        screen: App
      },
      TagDetail: {
        screen: TagDetail
      },
      FeedDetail: {
        screen: FeedDetail
      },
      UserDetail: {
        screen: UserDetail
      },
      SettingsPage: {
        screen: SettingsPage
      },
      AboutPage: {
        screen:About
      }
    },{
      headerMode: 'none'
    });
    
    
    export default class Root extends Component {
      render() {
        return (
          <Provider store={store}>
            <Apps/>
          </Provider>
        )
      }
    }
    
    
    AppRegistry.registerComponent(appName, () => Root);
    
    const Apps = createAppContainer(AppNavigator);
    //export default Apps;
    
    
    包.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"
      }
    }
    
    
    
    应用程序.json
    {
      "name": "TestApp",
      "displayName": "TestApp"
    }
    

    最佳答案

    如果循环在您自己的代码中,则必须将一些导出提取到第三个模块/文件中,然后将代码导入到之前形成循环的两个模块中。
    This may help

    关于javascript - react 原生 "Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67443639/

    相关文章:

    javascript - 从 redux-simple-router children 访问 redux store

    javascript - Javascript 字符串怎么不是对象?

    javascript - 提高性能 p5.js Metaballs

    javascript - Controller 中两个变量之间的差异

    android - 如何在Android中使用Facebook sdk 4.7.0和自定义Google Plus登录按钮制作自定义Facebook登录按钮

    android - ApplicationStatus类E/SysUtils:ApplicationStatus中的ApplicationContext为null

    java - 错误膨胀类...(CardView)

    javascript - 在 ionic cordova 中使用 javascript 修改 PDF 以添加按钮

    reactjs - OnSelect 不适用于 react-Google-places-autocomplete

    reactjs - 如何在 ASP.NET Core 3 React 应用程序的 index.html 中从服务器注入(inject)数据