Skip to content

Commit e1518e2

Browse files
fix(nextjs-mf): Do not attach runtime to api runtime chunks (#2571)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 031454d commit e1518e2

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

.changeset/sharp-dryers-sparkle.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+
Wrap require of federation runtime module in conditional so that async boundary plugin doesnt crash runtimes who do not implement federation

.github/workflows/build-and-test.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,26 @@ jobs:
4646
- name: Run Affected Test
4747
run: npx nx affected -t test --parallel=3 --exclude='*,!tag:type:pkg' --skip-cache
4848

49-
# - name: E2E Test for Next.js Dev
50-
# run: |
51-
# pnpm run app:next:dev &
52-
# sleep 1 &&
53-
# npx wait-on tcp:3001 &&
54-
# npx wait-on tcp:3002 &&
55-
# npx wait-on tcp:3000 &&
56-
# npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=2 &&
57-
# lsof -ti tcp:3000,3001,3002 | xargs kill
58-
59-
# - name: E2E Test for Next.js Prod
60-
# run: |
61-
# pnpm run --filter @module-federation/3002-checkout --filter @module-federation/3000-home --filter @module-federation/3001-shop build &&
62-
# pnpm run app:next:prod &
63-
# sleep 2 &&
64-
# npx wait-on tcp:3001 &&
65-
# npx wait-on tcp:3002 &&
66-
# npx wait-on tcp:3000 &&
67-
# npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=1 &&
68-
# lsof -ti tcp:3000,3001,3002 | xargs kill
49+
- name: E2E Test for Next.js Dev
50+
run: |
51+
pnpm run app:next:dev > /dev/null 2>&1 &
52+
sleep 1 &&
53+
npx wait-on tcp:3001 &&
54+
npx wait-on tcp:3002 &&
55+
npx wait-on tcp:3000 &&
56+
npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=3 &&
57+
lsof -ti tcp:3000,3001,3002 | xargs kill
58+
59+
- name: E2E Test for Next.js Prod
60+
run: |
61+
pnpm run --filter @module-federation/3002-checkout --filter @module-federation/3000-home --filter @module-federation/3001-shop build &&
62+
pnpm run app:next:prod &
63+
sleep 2 &&
64+
npx wait-on tcp:3001 &&
65+
npx wait-on tcp:3002 &&
66+
npx wait-on tcp:3000 &&
67+
npx nx run-many --target=test:e2e --projects=3000-home,3001-shop,3002-checkout --parallel=1 &&
68+
lsof -ti tcp:3000,3001,3002 | xargs kill
6969
7070
- name: E2E Test for ModernJS
7171
run: npx nx run-many --target=test:e2e --projects=modernjs --parallel=1 && lsof -ti tcp:4001 | xargs kill

packages/enhanced/src/lib/container/AsyncBoundaryPlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ class AsyncEntryStartupPlugin {
314314

315315
if (shouldInclude) {
316316
initialEntryModules.push(
317-
`__webpack_require__(${JSON.stringify(entryModuleID)});`,
317+
`if(__webpack_require__.m[${JSON.stringify(entryModuleID)}]) {
318+
__webpack_require__(${JSON.stringify(entryModuleID)});
319+
} else {
320+
console.warn('Federation Runtime Module not found. In the current runtime');
321+
}`,
318322
);
319323
}
320324
}

packages/nextjs-mf/src/plugins/container/InvertedContainerRuntimeModule.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class InvertedContainerRuntimeModule extends RuntimeModule {
3131
return '';
3232
}
3333

34+
if (this.chunk.runtime === 'webpack-api-runtime') {
35+
return '';
36+
}
3437
const { name } = this.options;
3538
const containerEntryModule = this.findEntryModuleOfContainer() as
3639
| Module

0 commit comments

Comments
 (0)