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

问题描述

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-navigationI 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有什么建议吗?

invariantbrowser.js:38:14runApplicationAppRegistry.js:193:13__callFunctionMessageQueue.js:425:19__guard$argument_0MessageQueue.js:112:6__guardMessageQueue.js:373:10callFunctionReturnFlushedQueueMessageQueue.js:111:4callFunctionReturnFlushedQueue[native code]:0Any 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);

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

08-19 11:09