node.js - 不变违规:“main”尚未注册。在以下情况下可能会发生这种情况: * Metro(本地开发服务器)从错误的文件夹运行
问题描述
我已将我的 index.js 更改为此,因为我试图遵循这个 turorial:
https://www.youtube.com/watch?v=6soHPnHxHxI
import { registerRootComponent } from 'expo';
import React from "react";
import { AppRegistry } from "react-native";
import App from "./App";
import { name as appName } from "./app.json";
import { Provider } from "react-redux";
import { Provider as PaperProvider } from "react-native-paper"
import store from "./store";
import 'react-native-gesture-handler';
const AppRedux = () => {
<Provider {...{store}}>
<PaperProvider>
<App></App>
</PaperProvider>
</Provider>
}
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in the Expo client or in a native build,
// the environment is set up appropriately
//AppRegistry.registerComponent(appName, () => AppRedux);
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in the Expo client or in a native build,
// the environment is set up appropriately
registerRootComponent(AppRedux);
但我不断收到此错误:
Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder.
解决方案
打开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”。
推荐阅读
- asp.net - 为什么我的 ASP.NET 网页使用某些文件扩展名引发自定义 404 错误
- r - 加载时无法将 col 类型更改为因子
- node.js - 在 Ubuntu 18.04 上安装 node-sass 失败
- javascript - 即使未选择 react-tabs 组件也会更改状态
- react-native - Bugsnag 无法读取未定义反应本机的通知
- r - R中的三变量堆积线/面积图
- pandas - 当存在缺失值时,熊猫可以推断出正确的列吗?
- windows - 在套接字(Winsock)阻塞接收调用后处理超时
- acumatica - Acumatica 帐户详细信息与历史库存估价报告不匹配
- reactjs - 静态文件、aspnet 核心 AddSpaStaticFiles roothpath、SPA 模板的 404 错误