Skip to content

[Bug]: Cannot share dependencies for mf consumer package #781

Closed
@yf-yang

Description

Version

System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 967.52 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Browsers:
    Chrome: 133.0.6943.98
    Safari: 16.3
  npmPackages:
    @rslib/core: * => 0.5.0

Details

I'm experimenting with rslib to achieve that:

  1. Create a lib package as module federation consumer
  2. Import the package to another app

Therefore, based on the official rslib example, I created the following structure:

  • A package, dep, contains a timestamp when the package is initially loaded
  • mf-remote, a mf provider that depends on dep
  • mf-react-component, a mf consumer. It loads mf-remote dynamically and it also imports from dep. I expect dep to be shared, which means it should only load once and timestamp should be the same. I also expect mf-react-component could be built as a lib.
  • mf-host, an app that imports from mf-react-component

Now I am not sure how to configure rslib.config.ts, I tried the following:

export default defineConfig({
  lib: [
    {
      format: "esm",
      // ...
    },
    {
      format: "cjs",
      // ...
    },
  ],
  // ...
  plugins: [
    pluginModuleFederation({
      name: "rslib_provider",
      exposes: {
        ".": "./src/index.tsx",
      },
      shared: {
        react: {
          singleton: true,
        },
        "react-dom": {
          singleton: true,
        },
        dep: {
          singleton: true,
        },
      },
    }),
  ],
});

However, it seems the output still imports/requires from dep instead of special module federation treatment.

My question is:

  1. Should the scenario (build a MF consumer as a lib) be supported?
  2. If so, is it currently supported? How to adjust the configuration?

Reproduce link

https://github.com/yf-yang/rslib-experiments

Reproduce Steps

pnpm i
pnpm build:lib
pnpm dev:all:host

Check logs

timestamp from host and timestamp from remote are different

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions