Skip to content

Commit 5c17bc4

Browse files
fix: normalize bundler runtime import paths (#1997)
Co-authored-by: Zack Jackson <[email protected]>
1 parent 845bc52 commit 5c17bc4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.changeset/soft-days-chew.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+
normalize bundler runtime import paths

packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,29 @@ class FederationRuntimePlugin {
4646

4747
static getTemplate(runtimePlugins: string[], bundlerRuntimePath?: string) {
4848
// internal runtime plugin
49+
const normalizedBundlerRuntimePath = (
50+
bundlerRuntimePath || BundlerRuntimePath
51+
).replaceAll('\\', '/');
52+
4953
let runtimePluginTemplates = '';
5054
const runtimePLuginNames: string[] = [];
5155

5256
if (Array.isArray(runtimePlugins)) {
5357
runtimePlugins.forEach((runtimePlugin, index) => {
5458
const runtimePluginName = `plugin_${index}`;
55-
const runtimePluginPath = path.isAbsolute(runtimePlugin)
56-
? runtimePlugin
57-
: path.join(process.cwd(), runtimePlugin);
59+
const runtimePluginPath = (
60+
path.isAbsolute(runtimePlugin)
61+
? runtimePlugin
62+
: path.join(process.cwd(), runtimePlugin)
63+
).replaceAll('\\', '/');
5864

5965
runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
6066
runtimePLuginNames.push(runtimePluginName);
6167
});
6268
}
6369

6470
return Template.asString([
65-
`import federation from '${bundlerRuntimePath || BundlerRuntimePath}';`,
71+
`import federation from '${normalizedBundlerRuntimePath}';`,
6672
runtimePluginTemplates,
6773
`${federationGlobal} = {...federation,...${federationGlobal}};`,
6874
`if(!${federationGlobal}.instance){`,

packages/sdk/src/normalize-webpack-path.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export function getWebpackPath(
1616
const webpackLocationWithDetail = webpackErrLocation
1717
.replace(/[^\(\)]+/, '')
1818
.slice(1, -1);
19-
const webpackPath = webpackLocationWithDetail.split(':').slice(0, -2)[0];
19+
const webpackPath = webpackLocationWithDetail
20+
.split(':')
21+
.slice(0, -2)
22+
.join(':');
2023
if (options?.framework === 'nextjs') {
2124
if (webpackPath.endsWith('webpack.js')) {
2225
return webpackPath.replace('webpack.js', 'index.js');

0 commit comments

Comments
 (0)