English 中文(简体)
违反《公约》的情况:没有登记“主要”
原标题:Invariant Violation: "main" has not been registered

New to React Native:

我开始了一个有博览会的新品牌项目,然后,我遵循https://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 (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.
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

任何建议?

问题回答

开放<代码>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 });
}

如果您有这一错误,请参见。 违反情况:“主要”没有登记,你必须替换<代码>。 www.un.org/spanish/ga/president

Another example :

如果你有这一错误,请替换<代码>。 www.un.org/spanish/ga/president

www.un.org/Depts/DGACM/index_spanish.htm For:

开放式<代码>。

/**
   * 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 of MainActivity.java <>/code> and index.js mustcompet.

问题是,如果你使用权宜之计,那么你就必须以不同方式登记。 全部资料载于:https://docs.expo.io/versions/latest/sdk/register-root-component/“rel=“noreferer”>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);

这为我工作:

  1. delete node_modules and your lockfile (package-lock.json / yarn.lock)
  2. change the expo package version in package.json to 38.0.8
  3. run yarn or npm install
  4. run expo install react-native-safe-area-context

<>index.js

AppRegistry.registerComponent("X", () => Root);

如果您在<代码>Android <>/code>中正面临这一问题,则确保<代码>mainactive.javaindex.js包含相同的“X”

<>主要活动>。

@Override
protected String getMainComponentName() {
   return "X";
}

如果您在<代码>iOS中正面临这一问题,则确保<代码>AppDelegate.m和index.js中包含相同的“X”

AppDelegate.m

 RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"X" initialProperties:nil];

In my case, the problem was solved when I called

AppRegistry.registerComponent(appName.toLowerCase())(=> App);

in index.js. So it looks like the first parameter is to be passed based on what error message is shown. In my case, my project name was AwesomeProject and the error reported by Metro was:

Invariant Violation: “awesomeproject” 尚未登记。

因此,我估计,在LowerCase(LowerCase)上加一会解决问题,它确实是!

然而,在试图使用<条码>npx反应-nativepr-macos在马科斯群岛上运行时,我正面临这一问题。

最后,我通过登记申请两次工作:

AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerComponent(appName.toLowerCase(), () => App);

还与<代码>npx反应-native-android合作。

workarounded by:

AppRegistry.registerComponent( main , () => App);

在我的案件中,我缺少一些必须安装的包裹。

npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

页: 1

import { AppRegistry, Platform } from "react-native";
import { registerRootComponent } from "expo";
import App from "./App";
import { name as appName } from "./app.json";

// 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
if (Platform.OS == "android") {
  registerRootComponent(App);
} else {
  AppRegistry.registerComponent(appName, () => App);
}

你在主要行为方式上的用词必须与MainComponentName一样。 java。

就我而言,我有一个完全用来模仿肉类结构的类别,即不是反应型成分。 我原打算出口这一类产品,但在申请
时称其为新甲型(foo, 条......)
,并触发了这一错误。 我发现,我只是把我的步骤追踪到我开始发现这一错误之前的最新补充。

进口名称:app.json 类似:

import {name as appName} from  ./app.json ;

之后在登记册中添加姓名。 构成部分

AppRegistry.registerComponent(appName, () => App);

In my case it a specific package called graphql-type-json that was the problem. So the 2nd part of the error was referring to the real issue:

  • A module failed to load due to an error and AppRegistry.registerComponent wasn t called."

装饰包裹有误:Syntax Error: 预期名称,发现“}”,从而停止了装货,并重犯了Invariant Violation错误。

在完全删除图表Kl-类型json(用药删除图表ql-类型json)包后,便再次装上罚款。

造成这一错误的主要原因是,出于某种原因,申请人没有正常运作。 这可能是因为你从一个错误的夹子上操作服务器。 在我的案件中,我总是会发现另一个错误以及这一错误,因此我保留了这些错误,这一错误自动解决。

If you have changed the application and package name using react-native-rename, in the file ios/AppName/AppDelegate.mm Synchronize the application name with the app.json file by finding the lineUIView *rootView = RCTAppSetupDefaultRootView(bridge, @"AppName", nil);

我对诊断这些痕迹并不大,但我的项目只是突然开始 throw倒这一错误。 我安装了react-native-skeleton-content,然后将错误写进react-native-gesture-handler。 页: 1 我认为,姿态手只是其他一些同行依赖更新的结果。

I uninstalled both and voila. The expo server runs again and processes the app just fine. Had I slept on it I never would have known but yeah, as a newbie, try deleting a new package you just installed and it s dependencies. It s likely the cause of a new issue.

就OS而言,我们需要在ios>appName>AppDelegate.mm/code>文档中再作一改动。

查询网站:http://www.c/em.htm

删除节点单元和<代码>包装_lock.json,并为我安装了Npm或 yarn :

  1. Delete these folders
  2. Run npm install or yarn install

我在我的项目中解决了这个问题:

删除节点单元

rm -rf node_modules

随后又重新排列:

npm install

之后,见index.js。 我把我的进口用具替换为:

import { name as app } from "./app.json"

之后,见index.js。 我将守则改为:

AppRegistry.registerComponent(app, () => App)

希望!

Try import NavigationContainer from @react-navigation/native and annex all the Code within NavigationContainer. 它为我工作!

这一错误是在指数.js中“主要”没有正确登记的情况下发生的。

您可使用<代码>registerRootComponent(App);或AppRegistry.registerComponent(“main”)=> App, 做同样的事情。

问题最有可能与你指数格不入。 你可以测试它,试图用一个空口 app,看你是否犯了同样的错误。

import { registerRootComponent } from "expo";
import React from "react";
import { View, Text } from "react-native";

const testApp = () => {
  return (
    <View>
      <Text>Test App</Text>
    </View>
  );
};

registerRootComponent(App);

如果这项工作,最有可能意味着在贵方收到更改后登记。 在我的案件中,我利用React土著项目中的“React”图书馆。 取消进口说明解决这一问题。 我建议,在某个时候重新采用你的每一部分,并看到哪一部分中断了。 或者说,当问题没有发生时,再回到先前的承诺中去,看到该项目增加了哪些图书馆。

引文:https://docs.expo.dev/troublefireing/application-has-not-been-registered/

In my case, I solved this by adding ExpoModulesProvider.swift into Xcode Build Phase -> Compile Sources.

“add<<>>>

最后,我找到了为我工作的解决办法!

我只是再次执行:

npm install -g expo-cli

ps.: 就我而言,这可能是因为我试图安装Turtle CLI,不得不将其移至免费磁盘空间。 这可能会腐蚀 exp案卷。

以下是我的工作:

AppRegistry.registerComponent( main , () => App);

可在你使用<代码>前签字/code>后进行,在您的<代码>Podfile/中,AppDelegate.m是特定进口的第3个缔约方图书馆,如<代码>react-native-maps,或

您需要将这些进口重新列入<代码>Podfile /AppDelegate.m, 下一个<代码>cd ios ,下个podstal/code>。 但是,expostartmight be not sufficient , 且您需要利用Xcode构建你的项目。 在建造和安装之后;在<代码>Xcode上操作你的代码后,该错误将发生,代号将开始。

<代码>Expo<>/code>和Xcode建立/模拟该附件,但在很早的阶段就对这些差异进行区分,两者之间有一些差别。 我还注意到,有时需要首先在<代码>Xcode上建立项目,首先,如果在<代码>模拟<<>>>上安装的传真机/密码>上安装了该信,然后才能从通过<代码>expostart-dev-client发射的模拟器上操作该信。 否则,我就错了。

Error: The development client (com.XYZ.ABC) for this project is not installed. Please build and install the client on the simulator first.orInvariant Violation: Native module cannot be null.orInvatian Violation: main has not been registered...





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签