From 847c5d02062473585c41bc23bc79a30ad882b042 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Thu, 28 Nov 2024 10:54:27 +0000 Subject: [PATCH] fix(module-federation): use 'hoisted' runtime for node to prevent issues with eager sharing --- .../angular/with-module-federation-ssr.ts | 9 +++++++++ .../rspack/with-module-federation-ssr.ts | 5 +++++ .../webpack/with-module-federation-ssr.ts | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts b/packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts index a5ceaef6bf546..7706461e4208d 100644 --- a/packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts +++ b/packages/module-federation/src/with-module-federation/angular/with-module-federation-ssr.ts @@ -47,10 +47,19 @@ export async function withModuleFederationForSSR( shared: { ...sharedDependencies, }, + remoteType: 'script', + library: { + type: 'commonjs-module', + }, /** * Apply user-defined config override */ ...(configOverride ? configOverride : {}), + experiments: { + federationRuntime: 'hoisted', + // We should allow users to override federationRuntime + ...(configOverride?.experiments ?? {}), + }, runtimePlugins: process.env.NX_MF_DEV_REMOTES && !options.disableNxRuntimeLibraryControlPlugin diff --git a/packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts b/packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts index 4a43ebb063b50..519aaf0cccc8a 100644 --- a/packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts +++ b/packages/module-federation/src/with-module-federation/rspack/with-module-federation-ssr.ts @@ -49,6 +49,11 @@ export async function withModuleFederationForSSR( * Apply user-defined config overrides */ ...(configOverride ? configOverride : {}), + experiments: { + federationRuntime: 'hoisted', + // We should allow users to override federationRuntime + ...(configOverride?.experiments ?? {}), + }, runtimePlugins: process.env.NX_MF_DEV_REMOTES && !options.disableNxRuntimeLibraryControlPlugin diff --git a/packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts b/packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts index 4c3c32b72d5d5..94a5b1fc5b8ce 100644 --- a/packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts +++ b/packages/module-federation/src/with-module-federation/webpack/with-module-federation-ssr.ts @@ -36,10 +36,19 @@ export async function withModuleFederationForSSR( shared: { ...sharedDependencies, }, + remoteType: 'script', + library: { + type: 'commonjs-module', + }, /** * Apply user-defined config overrides */ ...(configOverride ? configOverride : {}), + experiments: { + federationRuntime: 'hoisted', + // We should allow users to override federationRuntime + ...(configOverride?.experiments ?? {}), + }, runtimePlugins: process.env.NX_MF_DEV_REMOTES && !options.disableNxRuntimeLibraryControlPlugin