Skip to content

[Module Federation] collision between modules of differents remotes. #5308

Closed
@penguintree

Description

@penguintree

Bug report

What is the current behavior?
A host consumes two different remotes.
Both remotes have the same file structure, i.e. both exposes ./src/main.js under different names.

remote package 1 :

const moduleFederation = new ModuleFederationPlugin({
   name: 'somePackage',
   filename: 'somePackage.entrypoint.js',
   exposes: {
      './x': './src/main'
   }
});

remote package 2 :

const moduleFederation = new ModuleFederationPlugin({
   name: 'anotherPackage',
   filename: 'anotherPackage.entrypoint.js',
   exposes: {
      './y': './src/main'
   }
});

host :

const moduleFederation = new ModuleFederationPlugin({
   name: 'host',
   filename: 'host.entrypoint.js',
   remotes: {
      'firstRemote': 'somePackage@http://localhost:9001/somePackage.entrypoint.js',
      'secondRemote': 'anotherPackage@http://localhost:9002/anotherPackage.entrypoint.js'
   }
});

In the host app, when using both federated modules, the first one overrides the second.

import firstPackage from 'firstRemote/x';
import secondPackage from 'secondRemote/y'; // here object from firstRemote/x is imported, but it's not the same instance.

If the current behavior is a bug, please provide the steps to reproduce.
This repository reproduces the bug.

What is the expected behavior?
Both modules from both remotes should be loaded independently, as the similarities in the exposed file name is merely a coincidence and is not known by the host.

Other relevant information:
webpack version: 5.50.0
Node.js version: 14.17.0
Operating System: Windows 10 20H2 19042.1110
Additional tools: n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions