module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.28k stars 184 forks source link

Cannot use shared module in .mjs file correctly #2702

Open Cybbin opened 3 days ago

Cybbin commented 3 days ago

Describe the bug

I shared vue deps in ModuleFederationPlugin

new ModuleFederationPlugin({
  name: "app3Module",
  filename: "remoteEntry.js",
  dts: false,
  shared: ["vue"],
})

When i use vue in .mjs file, vue cannot be used correctly. It seems to be imported as a module, not a function.

image

Reproduction

https://github.com/Cybbin/pj-module-federation/tree/main/app-3

Used Package Manager

npm

System Info

chrome

Validations

ScriptedAlchemy commented 3 days ago

when you share it, its probbably resolving to the "main" field in the plugin.

share vue/nestedPath/index.mjs or whatever the esm path to vue is.

ScriptedAlchemy commented 2 days ago

Vue.default seems to make the app render.

ScriptedAlchemy commented 2 days ago

vue: { import: "vue/dist/vue.js", }

put that for your shared

Cybbin commented 22 hours ago

vue: { import: "vue/dist/vue.js", }

put that for your shared

It works, thanks!