repack icon indicating copy to clipboard operation
repack copied to clipboard

Cannot load local chunks: cannot read property loadScript of undefined

Open StanislavSava opened this issue 3 years ago • 0 comments

Environment

React Native 0.69.5

Description

Since upgrading to 3.0, the ScriptManager seems to fail to load scripts with the error of "cannot read property loadScript of undefined"

Screenshot 2022-10-04 at 12 40 58

Reproducible Demo

Here's my scriptManager

ScriptManager.shared.setStorage(AsyncStorage);
ScriptManager.shared.addResolver(async (scriptId, caller) => {
  // In dev mode, resolve script location to dev server.
  if (__DEV__) {
    return {
      url: Script.getDevServerURL(scriptId),
      cache: false
    };
  }
  // In production, get chunks matching the regex from filesystem.
  if (/^.+\.remote$/.test(scriptId)) {
    return {
      url: Script.getRemoteURL(`https://my-domain.dev/${scriptId}`)
    };
  } else {
    return {
      url: Script.getFileSystemURL(scriptId)
    };
  }
});

And I'm using React.Lazy to import the file

const Screen = React.lazy(
  () =>
    import(/* webpackChunkName: "async_body" */ './Screen')
);

And this is the extraChunks in webpack config

extraChunks: [
          {
            include: /.*/,
            type: 'local'
          },
          {
            // IMPORTANT!
            exclude: /^.+\.remote$/,
            type: 'remote',
            outputPath: path.join('build/output', platform, 'remote') // Default path
          }
        ]

StanislavSava avatar Oct 04 '22 09:10 StanislavSava