Skip to content

[Bug]: Multiple federation plugin usage doesn't work #352

@crutch12

Description

@crutch12

Describe the bug

You can't generate more then one remoteEntry.js file per one vite application.

It doesn't fail on build, but it doesn't work properly in runtime.

Vite config example:

plugins: [
  federation({
    name: 'firstRemote',
    filename: 'firstRemoteEntry.js',
    exposes: {
      './App1': './src/App1.vue',
    },
    shared: {
      vue: {},
    },
  }),
  federation({
    name: 'secondRemote',
    filename: 'secondRemoteEntry.js',
    manifest: { fileName: 'mf-manifest2.json' }, // generates correctly
    exposes: {
      './App2': './src/App2.jsx',
    },
    shared: {
      react: {},
    },
  }),
]

When you load thes remoteEntries:

import { App1 } from '@namespace/viteViteRemote';
import { App2 } from '@namespace/viteViteRemote2';

You get error:

Uncaught Error: Module ./App1 does not exist in container.

Looks like there is conflict between two mf remote entries and it takes only the last federation config, thus App2 works and App1 fails

Moreover: second "federation" plugin call breaks the first call. Now only secondRemote works, firstRemote is broken.

I get this problem in both ways:

  • with pure remoteEntry.js
  • using mf-manifest.json

Version

v1.9.0

Reproduction

https://github.com/crutch12/vite-module-federation/tree/reproduction/multiple-federation

Relevant log output

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions