File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed
packages/enhanced/src/wrapper Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @module-federation/enhanced ' : patch
3+ ---
4+
5+ fix(enhanced): replace require with lazyRequire to ensure proper initialization ordering in plugins
Original file line number Diff line number Diff line change 11import type { WebpackPluginInstance , Compiler } from 'webpack' ;
22import { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path' ;
33
4+ // Use module.require instead of require to prevent bundlers (rolldown/tsdown) from
5+ // hoisting the call to the top of the file. This ensures the require only executes
6+ // at call time, preserving strict initialization ordering. CJS-only.
7+ const lazyRequire = ( id : string ) : any => module . require ( id ) ;
8+
49/**
510 * Base Wrapper Plugin Class
611 *
@@ -33,7 +38,7 @@ export default abstract class BaseWrapperPlugin implements WebpackPluginInstance
3338 process . env [ 'FEDERATION_WEBPACK_PATH' ] || getWebpackPath ( compiler ) ;
3439
3540 // Lazily load core plugin after webpack path is set.
36- const CorePlugin = require ( this . coreModulePath ) . default as any ;
41+ const CorePlugin = lazyRequire ( this . coreModulePath ) . default as any ;
3742
3843 // Create core plugin instance and apply it
3944 this . createCorePluginInstance ( CorePlugin , compiler ) ;
Original file line number Diff line number Diff line change 11import type { Compilation } from 'webpack' ;
22import BaseWrapperPlugin from './BaseWrapperPlugin' ;
33
4+ // Use module.require instead of require to prevent bundlers (rolldown/tsdown) from
5+ // hoisting the call to the top of the file. This ensures the require only executes
6+ // at call time, preserving strict initialization ordering. CJS-only.
7+ const lazyRequire = ( id : string ) : any => module . require ( id ) ;
8+
49const PLUGIN_NAME = 'FederationModulesPlugin' ;
510
611export default class FederationModulesPlugin extends BaseWrapperPlugin {
@@ -9,9 +14,10 @@ export default class FederationModulesPlugin extends BaseWrapperPlugin {
914 }
1015
1116 static getCompilationHooks ( compilation : Compilation ) {
12- const CoreFederationModulesPlugin =
13- require ( '../lib/container/runtime/FederationModulesPlugin' )
14- . default as typeof import ( '../lib/container/runtime/FederationModulesPlugin' ) . default ;
17+ const CoreFederationModulesPlugin = lazyRequire (
18+ '../lib/container/runtime/FederationModulesPlugin' ,
19+ )
20+ . default as typeof import ( '../lib/container/runtime/FederationModulesPlugin' ) . default ;
1521 return CoreFederationModulesPlugin . getCompilationHooks ( compilation ) ;
1622 }
1723
Original file line number Diff line number Diff line change @@ -103,8 +103,6 @@ export default class ModuleFederationPlugin extends BaseWrapperPlugin {
103103 if ( ! enableBridgePlugin && hasBridgeReact ) {
104104 compiler . hooks . afterPlugins . tap ( 'BridgeReactBaseAliasPlugin' , ( ) => {
105105 try {
106- const path = require ( 'path' ) ;
107- const fs = require ( 'fs' ) ;
108106 const bridgeReactBasePath = path . resolve (
109107 compiler . context ,
110108 'node_modules/@module-federation/bridge-react/dist/base.es.js' ,
You can’t perform that action at this time.
0 commit comments