repack icon indicating copy to clipboard operation
repack copied to clipboard

Error: Unhandled error. ([ScriptManager] Failed to load script:)

Open dothanhtam99 opened this issue 1 year ago • 3 comments

Ask your Question

I encountered a problem when moving from super app to another mini app and it crashed, and this only happened with android release files while in debug mode it worked completely normally.

This is the error that i get from firebase:

Fatal Exception: com.facebook.react.common.JavascriptException: Error: Unhandled error. ([ScriptManager] Failed to load script:)

This error is located at: in Lazy in Suspense in Unknown in Unknown in Unknown in Unknown in RCTView in Unknown in m in RCTView in Unknown in RNSScreen in Unknown in i in Suspense in Unknown in N in t in t in b in i in Suspense in Unknown in N in RNSScreenStack in ScreenStack in w in RCTView in Unknown in A in Unknown in Unknown in i in Unknown in Unknown in Unknown in Unknown in Unknown in Unknown in Unknown in f in Unknown in A in Unknown in Unknown in RNCSafeAreaProvider in Unknown in NativeBaseConfigProviderProvider in Unknown in Unknown in Unknown in RCTView in Unknown in RCTView in Unknown in t, stack: @1:5816222 value@1:2267478 @1:2269254 generatorResume@-1 t@1:6490118 s@1:6490366 @1:6282645 @1:6282672 @1:5177564 v@1:5176313 y@1:5176708 callReactNativeMicrotasks@1:5178951 value@1:5007810 @1:5005908 value@1:5007454 value@1:5005866 value@-1 value@-1

   at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:75)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:142)
   at com.facebook.react.bridge.JavaModuleWrapper.invoke(:21)
   at com.facebook.jni.NativeRunnable.run(SourceFile)
   at android.os.Handler.handleCallback(Handler.java:958)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage()
   at android.os.Looper.loopOnce(Looper.java:230)
   at android.os.Looper.loop(Looper.java:319)
   at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(:37)
   at java.lang.Thread.run(Thread.java:1012)
Ảnh màn hình 2024-05-29 lúc 16 57 26

"react-native": "0.73.4", "@callstack/repack": "^3.7.0", node: v21.7.1

dothanhtam99 avatar May 29 '24 10:05 dothanhtam99

hi @dothanhtam99,

I'm not able to deduce anything from the inf you've provided. Please provide a reproduction repository so that we can get to the bottom of this. I'm guessing this is some sort of configuration error, not accounting for the release environment - best to verify this by sharing your host app ScriptManager config

jbroma avatar May 29 '24 12:05 jbroma

hi @jbroma , This is my index.js file

/**

  • @format */

import { AppRegistry, Platform } from 'react-native'; import App from './src/App'; import { name as appName } from './app.json'; import { ScriptManager, Federated, Script } from "@callstack/repack/client"; import crashlytics from '@react-native-firebase/crashlytics'; import firebase from '@react-native-firebase/app';

if (!firebase.apps.length) { firebase.initializeApp(); } crashlytics().log('App mounted.'); // crashlytics().crash();

ScriptManager.shared.addResolver(async (scriptId, caller) => { const resolveURL = Federated.createURLResolver({ containers: { eRequest: https://github.com/HongQuang231/bundle_auth_app/raw/master/outputs/${Platform.OS}/remotes/[name][ext], iVay: https://github.com/HongQuang231/bundle_IVay_app/raw/master/outputs/${Platform.OS}/remotes/[name][ext], }, });

let url; if (caller === 'main') { url = Script.getDevServerURL(scriptId); } else { url = resolveURL(scriptId, caller); }

if (url) { return { url, cache: true, query: { platform: Platform.OS, }, verifyScriptSignature: 'strict', }; } else { console.error(Failed to resolve URL for script: ${scriptId}, caller: ${caller}); throw new Error(Failed to resolve URL for script: ${scriptId}); } });

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

dothanhtam99 avatar May 30 '24 02:05 dothanhtam99

@dothanhtam99 you shoud use resolveURL for your main chunk in in release as well, please change

let url;
if (caller === 'main') {
url = Script.getDevServerURL(scriptId);
} else {
url = resolveURL(scriptId, caller);
}

to

let url;
if (__DEV__ && caller === 'main') {
  url = Script.getDevServerURL(scriptId);
} else {
  url = resolveURL(scriptId, caller);
}

please see if that helps

jbroma avatar Jun 14 '24 15:06 jbroma

This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

github-actions[bot] avatar Jul 15 '24 00:07 github-actions[bot]

This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.

github-actions[bot] avatar Jul 29 '24 00:07 github-actions[bot]