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.27k stars 184 forks source link

@module-federation/runtime loadRemote - Cannot define property Symbol(mf_module_id) #2590

Closed nicotu01 closed 2 weeks ago

nicotu01 commented 3 weeks ago

Describe the bug

When loading remote, I have the error below :

Uncaught (in promise) TypeError: Cannot define property Symbol(mf_module_id), object is not extensible
    at Function.defineProperty (<anonymous>)
    at defineModuleId (index.esm.js:298:24)
    at index.esm.js:315:17
    at Module2.get (index.esm.js:292:37)

Reproduction

https://github.com/nicotu01/module-federation-runtime-error

Used Package Manager

npm

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz
    Memory: 10.27 GB / 15.46 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.20.1 - ~/.nvm/versions/node/v18.20.1/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v18.20.1/bin/npm
    pnpm: 8.15.6 - ~/.nvm/versions/node/v18.20.1/bin/pnpm
  Browsers:
    Chrome: 121.0.6167.160

Validations

nicotu01 commented 3 weeks ago

I works with @module-federation/runtime@0.1.16

ScriptedAlchemy commented 3 weeks ago

@nicotu01 are you using ESM modules?

nicotu01 commented 3 weeks ago

Yes, I'm using ESM modules. In project example, the host and the remote turns on Vite@5.2.0 with type module.
And I load remote like this :

init({
  name: "host",
  remotes: [
    {
      type: "esm",
      name: "remote",
      entry: "http://localhost:4173/assets/remoteEntry.js",
    },
  ],
});
loadRemote("remote/Counter");
ScriptedAlchemy commented 3 weeks ago

Ahh that's the problem. Esm objects cannot be modified. I have opened a pr that should help

ScriptedAlchemy commented 3 weeks ago

Been merged, should show up in next release