From e27d656ef370958c864b052123ec05579ac9fc01 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 13 Aug 2020 18:28:37 -0700 Subject: [PATCH] improve "not a registered callable module" error message (#28913) Summary: Motivation: `Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication).` is an error that happens rarely, and most SO answers end up recommending to use `react-native bundle` to work around. I stumbled upon this error the other day and it took me a while to figure out that the error was caused by the fact that my `entryFile` path was pointing to an existing but invalid file. I figured it would be nice to mention this because I believe this will be a frequent cause of the error. ## Changelog [General] [Changed] - improve "not a registered callable module error message" Pull Request resolved: https://github.com/facebook/react-native/pull/28913 Test Plan: tested locally with RNTester, prints ``` [Sun May 17 2020 18:15:55.396] ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). This can happen when the application entry file path is incorrect. On Android, verify 'getJSMainModuleName()' in 'MainApplication.java' and 'project.ext.react.entryFile' in 'android/app/build.gradle'. On iOS, verify '- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge' in 'AppDelegate.m' and 'ENTRY_FILE' env. variable passed to 'react-native-xcode.sh' (if any) in 'Build Phases' -> 'Bundle React Native code and images'. ``` in metro logs Reviewed By: mdvacca Differential Revision: D23107228 Pulled By: fkgozali fbshipit-source-id: 0712ed7e593ba96b041578bafdbefcd09a3994b7 --- Libraries/BatchedBridge/MessageQueue.js | 9 +++------ Libraries/BatchedBridge/__tests__/MessageQueue-test.js | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index c1314d9ea794d0..fa2147b540d299 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -404,15 +404,12 @@ class MessageQueue { const moduleMethods = this.getCallableModule(module); invariant( !!moduleMethods, - 'Module %s is not a registered callable module (calling %s)', - module, - method, + `Module ${module} is not a registered callable module (calling ${method}). A frequent cause of the error is that the application entry file path is incorrect. + This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.`, ); invariant( !!moduleMethods[method], - 'Method %s does not exist on module %s', - method, - module, + `Method ${method} does not exist on module ${module}`, ); moduleMethods[method].apply(moduleMethods, args); Systrace.endEvent(); diff --git a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js index fb720c7b9ba991..e1b7fd84d32411 100644 --- a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js +++ b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js @@ -108,7 +108,8 @@ describe('MessageQueue', function() { const unknownModule = 'UnknownModule', unknownMethod = 'UnknownMethod'; expect(() => queue.__callFunction(unknownModule, unknownMethod)).toThrow( - `Module ${unknownModule} is not a registered callable module (calling ${unknownMethod})`, + `Module ${unknownModule} is not a registered callable module (calling ${unknownMethod}). A frequent cause of the error is that the application entry file path is incorrect. + This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.`, ); });