webpackvuejs2webpack-module-federation

ScriptExternalLoadError: Loading script failed. vue-cli@5.0.0-rc.0


We are trying microfrontends with ModuleFederationPlugin from Webpack 5.61.0 . I feel so helpless. I'm using @vue/cli@5.0.0-rc.0. The vue.config.js which exposes its modules looks like below,

const ModuleFederationPlugin =  require("webpack/lib/container/ModuleFederationPlugin");
const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
  publicPath: "http://localhost:8080/",
  configureWebpack: {
    plugins: [
      new ModuleFederationPlugin({
        name: "items",
        filename: "remoteEntry.js",
        exposes: {
          "./ItemsBase": "./src/components/ItemsBase.vue"
        },
        shared: require("./package.json").dependencies
      })
    ]
  },
  transpileDependencies: [
    'vuetify'
  ]
})

And the consumer's vue.config.js looks like this,

const ModuleFederationPlugin =  require("webpack/lib/container/ModuleFederationPlugin");
const { defineConfig } = require('@vue/cli-service');
module.exports = defineConfig({
  publicPath: "http://localhost:8081/",
  configureWebpack: {
    plugins: [
      new ModuleFederationPlugin({
        name: "my_shop",
        filename: "remoteEntry.js",
        remotes: {
          "items": "items@http://localhost:8080/remoteEntry.js"
        },
        shared: require("./package.json").dependencies
      })
    ]
  },
  transpileDependencies: [
    'vuetify'
  ]
})

I have the bootstrap.js in both projects an I'm importing it like import('./bootstrap') from main.js On the consumer project we are trying to import the remote component like this.

<template>
  <div class="home">
    <ItemsBase></ItemsBase>
  </div>
</template>

<script>
// @ is an alias to /src
export default {
  name: 'HomeView',
  components: {
    ItemsBase: () => import("items/ItemsBase")
  }
}
</script>

And this mix is based on webpack examples with vue-cli: https://github.com/module-federation/module-federation-examples/tree/master/vue-cli

The only difference is that they are using vue-cli@5.0.0-beta.3 but both have same webpack version(my prototypes and webpack samples).

Now the interesting part is that I'm getting the following error in the consumer project.

ScriptExternalLoadError: Loading script failed

any ideas?

Edit: Another difference is that the vue-cli sample from webpack is using yarn and I'm using npm which is just irrelevant but thought maybe it worths mentioning because their example works!!!

Edite: The issue is being followed on github

https://github.com/vuejs/vue-cli/issues/6823


Solution

  • I had the same problem and got it to work with vue-cli@5.0.0-rc.0. What i did was to delete the splitChunks before loading the MF like this:

    config.optimization.delete('splitChunks');