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.54k stars 237 forks source link

fix(enhanced): Do not inject the federation runtime into build time chunk #3225

Open lnlfps opened 2 days ago

lnlfps commented 2 days ago

Describe the bug

When working with umijs or father, during the compilation of less modules, some 'build time chunks' are generated. These temporary chunks lack chunkGraph information, leading to errors when generating runtime code.

// enhanced/scr/lib/container/runtime/FederationRuntime.ts 49

const conditionMap = this.compilation.chunkGraph.getChunkConditionMap(
  this.chunk,
  chunkHasJs,
);

Then The current chunk id is build time chunk, the variable this.compilation.chunkGraph is undefined,causing an exception to be thrown

Suggestion

If the chunk's id is build time chunk, do not inject the federation runtime to this chunk. like this:

image

Reproduction

-

Used Package Manager

npm

System Info

-

Validations

ScriptedAlchemy commented 1 day ago

Send a pull request