gpt4 book ai didi

javascript - 不变违规 : "main" has not been registered

转载 作者:行者123 更新时间:2023-12-01 15:24:38 25 4
gpt4 key购买 nike

React Native 新手:
我使用 Expo init 开始了一个全新的项目,然后按照 https://reactnavigation.org/docs/hello-react-navigation 中提到的说明进行操作
我使用 expo start 运行项目,但出现此错误。
不变违规:“main”尚未注册。在以下情况下可能会发生这种情况:

  • Metro(本地开发服务器)从错误的文件夹运行。检查 Metro 是否正在运行,将其停止并在当前项目中重新启动。
  • 由于错误和 AppRegistry.registerComponent 导致模块加载失败没有被调用。

  • 不变的
    browser.js:38:14
    运行应用程序
    AppRegistry.js:193:13
    __callFunction
    消息队列.js:425:19
    __guard$argument_0
    消息队列.js:112:6
    __ guard
    消息队列.js:373:10
    callFunctionReturnFlushedQueue
    消息队列.js:111:4
    callFunctionReturnFlushedQueue
    [ native 代码]:0
    有什么建议么?

    最佳答案

    打开index.js ,文件的内容应该是这样的:

    import { AppRegistry, Platform } from 'react-native';
    import App from './App';

    AppRegistry.registerComponent('X', () => App);

    if (Platform.OS === 'web') {
    const rootTag = document.getElementById('root') || document.getElementById('X');
    AppRegistry.runApplication('X', { rootTag });
    }
    如果您遇到此错误 Invariant Violation: “main” has not been registered您必须更换 'X'通过 'main' .
    另一个例子 :
    如果您遇到此错误 Invariant Violation: “app” has not been registered您必须更换 'X'通过 'app' .
    对于安卓:
    打开 ./android/app/src/main/java/[multiple folders]/MainActivity.java
    /**
    * Returns the name of the main component registered from JavaScript.
    * This is used to schedule rendering of the component.
    */
    @Override
    protected String getMainComponentName() {
    return "X";
    }
    'X'MainActivity.javaindex.js必须匹配。

    关于javascript - 不变违规 : "main" has not been registered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62649381/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com