Skip to content

MF v1.0 shared dependencies at build time are not shared with MF v1.5 runtime #2541

@markmssd

Description

@markmssd

Describe the bug

I am using the Advanced API Dynamic Remotes example: https://github.com/module-federation/module-federation-examples/tree/master/advanced-api/dynamic-remotes, and trying out the Webpack version (pnpm legacy:start).

I wanted to try loading the apps when:

  • Remotes use Module Federation v1 (from Webpack)
  • Host also uses Module Federation v1 (from Webpack) at build time to defined shared (but not remotes)
  • Host loads Remotes at runtime (using @module-federation/runtime package)

I have created the minimum required to reproduce it at https://github.com/markmssd/module-federation-runtime-shared. You can try it with pnpm start:legacy. The only difference between this reproducible and the official example is that in the Webpack configs, I am using the Webpack MF plugin from require('webpack').container.ModuleFederationPlugin, and uninstalled @module-federation/enhanced completely.

It seems like it doesn't load the shared dependencies properly. First, when we start the app, and log __FEDERATION__ in the developer console, it shows no shared dependencies.

Screenshot 2024-05-25 at 6 23 54 PM

Then, if we load App3, it crashes with

Screenshot 2024-05-25 at 5 54 17 PM

which is usually an error when multiple instances of React are used.

Note what loading App2 works just fine, not sure why. The only difference with it is that it also shares moment, so not sure, I would have expected it to crash too 🤔

I've also noticed that if I define the shared dependencies on runtime too in App1 (and I can then remove MF plugin completely from its Webpack), then it works properly. I guess this is expected, obviously.

My question is, shouldn't the shared dependencies defined with MF v1 (using require('webpack').container.ModuleFederationPlugin in Webpack) be detected by the Runtime MF in the host as well?

I'd be happy to open a PR with some guidance if this is indeed a bug and not expected. Let me know!

Reproduction

https://github.com/markmssd/module-federation-runtime-shared

Used Package Manager

pnpm

System Info

The command fails, but I am on `MacOS M1`, `Chrome v125`

Validations

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions