不变违规:“主要"尚未注册 [英] Invariant Violation: "main" has not been registered

查看:48
本文介绍了不变违规:“主要"尚未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

New to React Native: I started a brand new project with Expo init and then I followed the instructions mentioned inhttps://reactnavigation.org/docs/hello-react-navigation I run the project with expo start and I get this error. Invariant Violation: "main" has not been registered. This can happen if:

  • Metro(本地开发服务器)从错误的文件夹运行.检查 Metro 是否正在运行,在当前项目中将其停止并重新启动.
  • 模块因错误而无法加载,并且 AppRegistry.registerComponent 未被调用.
  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called.

不变的browser.js:38:14运行应用程序AppRegistry.js:193:13__call 函数MessageQueue.js:425:19__guard$argument_0MessageQueue.js:112:6__警卫MessageQueue.js:373:10callFunctionReturnFlushedQueueMessageQueue.js:111:4callFunctionReturnFlushedQueue[本机代码]:0有什么建议吗?

invariant browser.js:38:14 runApplication AppRegistry.js:193:13 __callFunction MessageQueue.js:425:19 __guard$argument_0 MessageQueue.js:112:6 __guard MessageQueue.js:373:10 callFunctionReturnFlushedQueue MessageQueue.js:111:4 callFunctionReturnFlushedQueue [native code]:0 Any suggestions?

推荐答案

问题在于,如果您使用的是 expo,那么您必须以不同的方式注册组件.所有信息都在文档中.https://docs.expo.io/versions/latest/sdk/注册根组件/

The problem is that if you are using expo then you have to registerComponent differently. All the information is in the docs. https://docs.expo.io/versions/latest/sdk/register-root-component/

import { registerRootComponent } from 'expo';
import React from 'react';
import { View } from 'react-native';

class App extends React.Component {
  render() {
    return <View />;
  }
}

registerRootComponent(App);

这篇关于不变违规:“主要"尚未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆