Open
Description
Hi!
I have encountered an issue when calling withModuleFederationPlugin with eager loading set to true:
TypeError: Cannot read properties of undefined (reading 'import')
at D:\Projects\SomeProject\libs\mf\src\utils\modify-entry-plugin.ts:20:20
at mergeEntry (D:\Projects\SomeProject\libs\mf\src\utils\modify-entry-plugin.ts:10:11)
at cfgOrRemove (D:\Projects\SomeProject\libs\mf\src\utils\modify-entry-plugin.ts:13:22)
at D:\Projects\SomeProject\libs\mf\src\utils\modify-entry-plugin.ts:18:12
at Array.forEach (<anonymous>)
at ModifyEntryPlugin.apply (D:\Projects\SomeProject\libs\mf\src\utils\modify-entry-plugin.ts:16:30)
at createCompiler (D:\Projects\SomeProject\node_modules\webpack\lib\webpack.js:76:12)
at create (D:\Projects\SomeProject\node_modules\webpack\lib\webpack.js:143:16)
at webpack (D:\Projects\SomeProject\node_modules\webpack\lib\webpack.js:167:32)
at Object.f [as webpackFactory] (D:\Projects\SomeProject\node_modules\webpack\lib\index.js:72:16)
I could figure it out that ModifyEntryPlugin cannot find 'style' entry in compiler.options.entry which is set in the createModifyEntryPlugin method in .\libs\mf\src\utils\with-mf-plugin.ts Ln 136 when eager loading is set to true.
export class ModifyEntryPlugin {
....
apply(compiler) {
...
const mergeEntry = (keyFn, key) => [
...(keyFn(this.config[key]) || []),
...(keyFn(compiler.options.entry[key]) || []), //<---------- Passes undefined if key is missing in compiler.options.entry
];
const cfgOrRemove = (objFn, valueFn, key) => {
const values = mergeEntry(valueFn, key);
return values.length > 0 ? objFn(values) : {};
};
Object.keys(this.config).forEach((key) => {
compiler.options.entry[key] = { //<---------- No check if there is an entry for the key
...cfgOrRemove(
(v) => ({ import: v }),
(c) => c.import, //<---------- Error: Cannot read properties of undefined (reading 'import'). c is undefined
key
),
...cfgOrRemove(
(v) => ({ dependOn: v }),
(c) => c.dependOn,
key
),
};
});
......
}
Is it my project specifiic issue (some ts, compiler options) or does the ModifyEntryPlugin plugin need to be fixed to add key exists check ?
Thank you!
Metadata
Metadata
Assignees
Labels
No labels