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.5k stars 230 forks source link

singleton dependency not working with sourcebuild #3134

Open yf-yang opened 3 days ago

yf-yang commented 3 days ago

Describe the bug

I am using modern.js's source build (rspack source build plugin I guess) with module federation. In the reproduction repo, there are three apps/packages

Now, if singleton-dep's dist/ folder does not exist, it is expected to use its source code for module federation. However, it does not work. The dist/ folder seems to be required.

I'd like to know if it is not supported, or I misconfigured something, or it is a bug.

To reproduce:

pnpm i
cd apps/app
pnpm dev

# open another shell
rm -r packages/singleton-dep/dist

From app's log, it shows it is expecting packages/singleton-dep/dist/es/index.js After dist/ is removed, app could not compile and says × resolving fallback for shared module singleton-dep, the app could not run either.

Reproduction

https://github.com/yf-yang/module-federation-sourcebuild-debug

Used Package Manager

pnpm

System Info

System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 21.04 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 22.4.1 - /usr/local/bin/node
    npm: 10.8.1 - /usr/local/bin/npm
    pnpm: 9.5.0 - /usr/local/bin/pnpm
    bun: 1.0.29 - ~/.bun/bin/bun
    Watchman: 2023.10.09.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 130.0.6723.70
    Safari: 16.3

Validations

ScriptedAlchemy commented 3 days ago

Use rslib?

yf-yang commented 3 days ago

@ScriptedAlchemy Could you be more specific?

I'm expecting:

In other words, without building dist/ folders in those dependencies packages, could they be used as module federation singleton packages?