Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
See original GitHub issuewebpack version: 5.20.0
error message
warining: Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed. error: Uncaught (in promise) ScriptExternalLoadError: Loading script failed.
similar issue: (#307)
I already used syntax like app2: "app2@http://localhost:3002/remoteEntry.js"
, but the browser still report the error.
Here’s my config:
app1
app2
other
I am sure I have read shared-routes2
folder in this repo.
The difference between my demo and shared-routes
is this different framework.
I use vue-cli in my demo.
I inspect the generated webpack config:
/* config.plugin('mf') */
// app1
new ModuleFederationPlugin(
{
name: 'app1',
filename: 'remoteEntry.js',
remotes: {
app2: 'app2@http://localhost:8082/remoteEntry.js'
},
exposes: {},
shared: {
vue: {
eager: true,
singleton: true,
requiredVersion: '^2.6.11'
},
'vue-router': {
eager: true,
singleton: true,
requiredVersion: '^3.4.3'
}
}
}
)
// app2
/* config.plugin('mf') */
new ModuleFederationPlugin(
{
name: 'app2',
filename: 'remoteEntry.js',
exposes: {
'./routes': './src/router/index.ts'
},
shared: {
vue: {
eager: true,
singleton: true,
requiredVersion: '^2.6.11'
},
'vue-router': {
eager: true,
singleton: true,
requiredVersion: '^3.4.3'
}
}
}
)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Webpack Module Federation Error ScriptExternalLoadError
I had a similar issue with specifying shared dependencies on a remote. I ended up having to disable splitChucks after reviewing your Github ......
Read more >ScriptExternalLoadError Loading script failed
This is regarding webpack Module Federation question. Created 2 react apps (remote and host) using npx create-mf-app. Rendered Simple Hello in ...
Read more >Migrating Module Federation from Webpack 5.0.0-beta.16 to ...
Uncaught ScriptExternalLoadError: Loading script failed. ... Uncaught Error: Shared module is not available for eager consumption:
Read more >webpack: examples/module-federation/README.md - Fossies
Sharing modules requires that all remotes are initialized // and can provide ... event.target.src; __webpack_error__.message = 'Loading script failed.
Read more >webpack/webpack - Gitter
If I use dependOn without an "import" it fails. if I say "myLib: ['sublib1' ... to new error Initialization of sharing external failed:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As mentioned by nrz2000 disabling splitChunks worked, but I didn’t understand why, so I checked vue-cli code to see how they were configuring SplitChunks plugin.
And here it is what I got so far:
Comparing the config from vue-cli and the default webpack config from the official website we can get some answers.
Code copied from vue-cli:
https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/app.js#L41-L60
Code copied from webpack docs:
https://webpack.js.org/plugins/split-chunks-plugin/#optimizationsplitchunks
So the main difference between the two configs is that webpack uses by default
chunks: 'async'
while vue-cli useschunks: initial
, and this seems to be the reason behind the error with module federation. I changed my vue-config to the following and it solved the problem:Note that it’s the same configuration as vue-cli, but just changing the
chunks
property on both cache groups frominitial
toasync
Still, I don’t know the specific reason, in this stackoverflow thread they explain the differences between the three possible split chunk values:
async
,all
andinitial
. I tried with ‘all’ and the error persists. I think it’s related to the nature of module federation that relies on async chunks, so trying optimizing static chunks throw errors, but I’m just speculating here. Hope someone has some answers.我这边发现问题了,是qiannkun沙箱问题,暂时通过配置library: { type: ‘window’, name: ‘xxx’ } 来解决