Skip to content

Commit 8a80605

Browse files
authored
fix(enhanced): consume shared module cache issue (#4102)
1 parent 6c550bf commit 8a80605

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.changeset/metal-keys-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
fix(enhanced): Mark all exports as provided, to avoid webpack's export analysis from marking them as unused since we copy buildMeta

packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
MIT License http://www.opensource.org/licenses/mit-license.php
3-
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy
44
*/
55

66
'use strict';
@@ -736,6 +736,10 @@ class ConsumeSharedPlugin {
736736
// This ensures ConsumeSharedModule inherits ESM/CJS detection (exportsType) and other optimization metadata
737737
module.buildMeta = { ...fallbackModule.buildMeta };
738738
module.buildInfo = { ...fallbackModule.buildInfo };
739+
// Mark all exports as provided, to avoid webpack's export analysis from marking them as unused since we copy buildMeta
740+
compilation.moduleGraph
741+
.getExportsInfo(module)
742+
.setUnknownExportsProvided();
739743
}
740744
}
741745
}

packages/enhanced/test/unit/sharing/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ export const createMockCompilation = () => {
202202
const mockModuleGraph = {
203203
getModule: jest.fn(),
204204
getOutgoingConnections: jest.fn().mockReturnValue([]),
205+
getExportsInfo: jest.fn().mockReturnValue({
206+
setUnknownExportsProvided: jest.fn(),
207+
}),
205208
};
206209

207210
// Cast to any to allow flexible property addition

0 commit comments

Comments
 (0)