react-native: Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope' when using main.jsbundle on iOS simulator

Hi, I’d like to bundle my app using the command

react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output iOS/main.jsbundle

from my project’s root directory. Bundling itself works just fine and the main.jsbundle file is created/updated. I’ve uncommented the line in AppDelegate.m that sets jsCodeLocation to my main bundle’s URL. As soon as I run my app in the simulator, chrome spits out the error

Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'file:///Users/steff/Library/Developer/CoreSimulator/Devices/9B63E242-5394-4781-9041-4408455B36B3/data/Containers/Bundle/Application/327E4FD3-77F7-4834-8CE7-44D68CE37B24/iazzu.app/main.jsbundle' failed to load.

When checking in Finder, the file exists and seems to have the same content than the .jsbundle file created by the bundle script.

Any ideas how I could solve this?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

I came across this error message when trying to run via the Android emulator. Turning off the debugger and reloading the app revealed there was a syntax error in my JSX. Once that was fixed, the error went away and the app ran properly with the debugger.

Looks like you are trying to debug offline bundle in Chrome, which doesn’t work because of browser’s offline content policy. Press Cmd+D, “Disable Chrome Debugging”

You get this error when you have a syntax error like @hirmes said. The way to deal with this currently is to disable remote debugging, then the red screen will tell you where it is. I will post another issue for this behaviour specifically.

The problem is that you are trying to use Chrome debugging with a JS file that is bundled with your app. You should use the packager server instead.

The Chrome debugger needs to load the JS from a server since it would be a security problem if webpages could randomly start reading files off of your disk. You can disable this security protection at your own risk with:

open /Applications/Google\ Chrome.app --args --allow-file-access-from-files

I am using version30 ,and now I have solved my problem by add NSURL *jsCodeLocation; [[RCTBundleURLProvider sharedSettings] setDefaults]; #if DEBUG [[RCTBundleURLProvider sharedSettings] setJsLocation:@"10.107.31.112"]; #endif before jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; in AppDelegate.m

@shmily617 I’ve been stucking for 2 days! That works like a charm! My react native version is 0.35.

@shmily617 that works for me, thanks!