Skip to content

Latest commit

 

History

History
49 lines (29 loc) · 848 Bytes

File metadata and controls

49 lines (29 loc) · 848 Bytes

NOTE

shard问题报错

错误信息: Uncaught Error: Shared module is not available for eager consumption

解决方法如下:

  • 方法一: 将报错模块的代码放到一个单独的文件例如:init.js中, 在主入口中使用import('./init.js')进行异步加载

    // bootstrap.js
    import _ from "lodash";
    console.log(_.add(1, 2));
    
    (async () => {
      const { sayHello } = await import("RemoteApp/utils");
      sayHello();
    })();
    
    console.log("Hello");
    
    // main.js
    import("./bootstrap");
  • // 方法二
    new ModuleFederationPlugin({
        // .....
        shared:{
            [module]:{
                eager:true
            }
        }
    }),

https://webpack.js.org/concepts/module-federation/#uncaught-error-shared-module-is-not-available-for-eager-consumption