“Invariant Violation: Application AwesomeProject has not been registered” When building for iOS device with static jsbundle

后端 未结 14 2303
刺人心
刺人心 2020-12-08 18:20

First off, I don\'t know react, but I figured deploying to an iOS device instead of the simulator wouldn\'t be too difficult to do with the docs. They were a bit sparse but

相关标签:
14条回答
  • 2020-12-08 18:36

    Your problem shouldn't have anything to do with the console, if you properly bundled your javascript into the ios app it wont be trying to talk to dev server, it'll just get the javascript from the bundle.

    From the error message I'd guess that you might have renamed your main component. Be sure that the 'AppName' you pass into the

    AppRegistry.registerComponent('AppName' /* <- */, ... )

    matches with the @"AppName" on your AppDelegate.m on the call for

    [[RCTRootView alloc] initWithBundleUrl:...
                                moduleName:@"AppName" // <-
                             launchOptions:...
    
    0 讨论(0)
  • 2020-12-08 18:38

    It is because the react-native server is still watching the old one. You need to shut the server down first.

    You could just kill the process.

    In terminal

    ps aux | grep react
    

    Kill or pkill the process and then

    npm start
    
    0 讨论(0)
  • 2020-12-08 18:41

    Got the same error, restarting everything including the xcode and terminal worked for me.

    0 讨论(0)
  • 2020-12-08 18:45

    I got the similar message in the console.

    message: Invariant Violation: Application AwesomeProject has not been registered."

    I just added REACT_EDITOR=atom on ~/.bashrc file.

    0 讨论(0)
  • I got this issue after renaming the project name and a couple of files. to solve it just make sure that the name of the app is the same in index.js app.json, MainActivity.java and AppDelegate.m.

    app.json

    { "name": "MyNewApp", "displayName": "MyNewApp" }
    

    index.js

    AppRegistry.registerComponent('MyNewApp', () => MyNewApp);

    MainActivity.java

    `@Override protected String getMainComponentName() {
    return "MyNewApp"; }
    
    0 讨论(0)
  • 2020-12-08 18:47

    AppRegistry defines the entry point to the application and provides the root component.

    Your first param doesn't match your project name.

    AppRegistry.registerComponent('AwesomeProject', () => YourMainComponent);
    

    First param of registerComponent has to be your project name, second param is anonymous function that returns your root react component.

    If first param doesn't match xcode project name, you get that error that your application has not been registered.

    In case you don't have AppRegistry in the scope you can call it like this React.AppRegistry.registerComponent or you can assign it to the AppRegistry var

    var {
      AppRegistry
    } = React;
    
    0 讨论(0)
提交回复
热议问题