react-native: Invariant Violation: "app" has not been registered - AppRegistry.js | runnables[appKey] is undefined
Description
After upgrading to 0.69 and upgrading a lot of packages, I’m not able to build Android anymore.
With iOS, there is no problem but Android is impossible to build.
A simple react-native run-android launch the app on the phone, but the app won’t appear. I only got this error :
ExceptionsManager.js:149 Invariant Violation: "app" 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.
So, after some search, I found the AppRegistry.js file (node_modules/eact-native/Librairies/ReactNative). There is a const named runnables[appKey], and with iOS, this show me a lot of informations, but with Android, I only got undefined.
Someone has the same problem ?
Version
0.69.0
Output of npx react-native info
System:
OS: macOS 12.6 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 116.24 MB / 16.00 GB Shell: 3.2.57 - /bin/bash
Binaries:
Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.17 - ~/Documents/myFiles/myProject/node_modules/.bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
Android NDK: 22.1.7171670
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9514443 Xcode: 13.2/13C90 - /usr/bin/xcodebuild
Languages:
Java: 19.0.2 - /usr/bin/javac Python: Not Found
npmPackages:
@react-native-community/cli: ^4.13.0 => 4.14.0 react: ^18.2.0 => 18.2.0 react-native: ^0.69.0 => 0.69.0 react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Upgrade React-Native to 0.69, and do react-native run-android.
Snack, code example, screenshot, or link to a repository
The error is here :
runApplication(
appKey: string,
appParameters: any,
displayMode?: number,
): void {
if (appKey !== 'LogBox') {
const logParams = __DEV__
? '" with ' + JSON.stringify(appParameters)
: '';
const msg = 'Running "' + appKey + logParams;
infoLog(msg);
BugReporting.addSource(
'AppRegistry.runApplication' + runCount++,
() => msg,
);
}
invariant(
runnables[appKey] && runnables[appKey].run,
`"${appKey}" has not been registered. This can happen if:\n` +
'* 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.\n' +
"* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.",
);
SceneTracker.setActiveScene({name: appKey});
runnables[appKey].run(appParameters, displayMode);
},
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 33
Can you please share the contents of the index.js file at the root of the project?
The error usually points to the code below which is found at
<root folder>/index.js. Also from version did you upgrade?in my case, there were 2 files left from the previous developer and for a long time I could not understand the cause of the error
Here we have App.js and index.js
with this code in index.js
and code in App.js
when a build is created, expo refers to App.js and does not see the AppRegistry.registerComponent there, to solve the problem, it is enough to replace all the code in App.js with the code from Index.js and everything will work
I still facing this issue while upgraded to react native 0.71.4 from 0.64 any solution for this issue I tried lots of solutions which are
Please any solution for reply this
This issue was cleared successfully. So anyone wants to resolve this make sure the below points are cleared
You saved me. After 3 hours of debugging, finally, the issue was due to the import issue in App.tsx. The error message definitely misleading.
Bad import in
App.jsorApp.tsxwill trigger this error.For example, when upgrading librairies some import breaking changes can happen :
import Component from ../pathBut now with the breaking change it is :
import { Component } from ../pathTry to comment out imports one by one and see if one comment clear the error. Then you just have to find documentation about the lib that triggers the error.
I had this error while upgrading React Native and I fixed it this way !
It has nothing to do with
appname.Resolved by deleting the build on my emulator and creating another build.
I am facing the same issue on iOS and react-native:0.73.2.
I had to take a close look of where the app was actually reading it’s entry point from using the Android Studio logging tool. On both builds it read from app.js or index.js(release and dev build). I just had to make sure both had the same content.
At the time I just needed a solution the problem, I haven’t researched as to why that was happening given that I had no prior interaction with those files.
An Issue - Yes that will work. I’ve not tried the new update to confirm if it’s something that has been resolved. You trying to solve this issue at this time means it probably hasn’t.
@vikil143 Tried debugging the issue, Understood that the issue is due to the ‘require’ statements in the js files. The error is thrown wherever export/import is used in tsx files ie; require in compiled js files. Trying to resolve it.
This error also caused when you running metro bundler of different project is not closed. So try to kill all metro bundlers as well as restart your PC check once
What else have you tried to fix this error?
Side note: https://github.com/facebook/react-native/commit/57774a4a981e2f12cfe9b029447e34f203221b18
./app.jsonI am using bare RN workflow. and also facing the same issue. I was used ”create-react-native-library“ to create a turbo module. After I use “npx react-native@latest run-ios --udid xxxx” to build application on my iphone. react-native version was upgrad to v0.74.3. On my iphone device I get 2 Error:
Invariant Violation: new NativeEventEmitter() requires a non-null argument.`Invariant Violation: “CppTurboExample” has not been registered. This can happen if:I am double check my appname. vs code => “root folder/example/app.json” . My appname is “CppTurboExample” xcode => “root folder/…/AppDelegate.mm”. the line 9 code is “self.moduleName = @“CppTurboExample”;” so my appname is looks same.
According to the following article. There are two best ways to fix it. React Native fucking error that i have been trynna fix for 22 hours now 1.creating a new react native project, then copy paste my code on it (I trying) 2.reinstall 2.1.Quit everything and restart machine 2.2.cd ios && pod install && cd… 2.3.Whatever recent npm package you installed, uninstall it. Then Build your app. 2.4.If these 3 fail, audition for a role on Living Alaska and become one with the wild
Upgradation of react-native to 0.71, react to 18, gradle, node and its respective dependencies
Can you send some more details like what are trying to do and what you did? and My suggestion is debug the code properly then you can get where is actual bug