Skip to content

Commit 890fff8

Browse files
fix(node): runtime plugin missing vars cause crash (#2471)
Co-authored-by: Zhang Hang <[email protected]> Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 2700ba1 commit 890fff8

File tree

18 files changed

+84
-349
lines changed

18 files changed

+84
-349
lines changed

.changeset/thirty-days-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/node': patch
3+
---
4+
5+
fix missing variable in runtime plugin when setting to global for script types

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ jobs:
7777
run: pnpm run app:manifest:dev & echo "done" && npx wait-on tcp:3009 && npx wait-on tcp:3012 && npx nx run-many --target=e2e --projects=3008-webpack-host --parallel=1 && lsof -ti tcp:3008,3009,3010,3011,3012 | xargs kill
7878

7979
- name: E2E Node Federation
80-
run: npx nx run-many --target=serve --projects=node-local-remote,node-remote --parallel=3 & echo "done" && sleep 10 && npx nx run-many --target=serve --projects=node-host & npx wait-on tcp:3333 && npx nx run node-host-e2e:test:e2e
80+
run: npx nx run-many --target=serve --projects=node-local-remote,node-remote --parallel=3 & echo "done" && sleep 25 && npx nx run-many --target=serve --projects=node-host & sleep 5 && npx wait-on tcp:3333 && npx nx run node-host-e2e:test:e2e

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/out-tsc
77
/build
88
/@mf-types
9+
**/@mf-types/**
910
/docs
1011
/.nx
1112
# dependencies

apps/3000-home/package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33
"version": "1.0.0",
44
"private": true,
55
"dependencies": {
6-
"acorn": "7.4.1",
76
"antd": "4.24.15",
87
"buffer": "5.7.1",
9-
"chrome-trace-event": "1.0.3",
108
"encoding": "0.1.13",
11-
"enhanced-resolve": "5.15.0",
129
"eslint-scope": "7.2.2",
13-
"eventemitter3": "5.0.1",
1410
"events": "3.3.0",
15-
"fast-glob": "3.3.2",
1611
"js-cookie": "3.0.5",
1712
"lodash": "4.17.21",
1813
"next": "14.1.2",
1914
"node-fetch": "2.7.0",
2015
"react": "18.2.0",
2116
"react-dom": "18.2.0",
2217
"schema-utils": "3.3.0",
23-
"semver": "6.3.1",
24-
"styled-jsx": "5.1.2",
25-
"tapable": "2.2.1",
2618
"terser-webpack-plugin": "5.3.10",
2719
"typescript": "5.3.3",
2820
"upath": "2.0.1",
2921
"url": "0.11.3",
30-
"util": "0.12.5",
31-
"webpack-sources": "3.2.3"
22+
"util": "0.12.5"
3223
},
3324
"devDependencies": {
3425
"@module-federation/nextjs-mf": "workspace:*",

apps/3001-shop/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"react-dom": "18.2.0",
2121
"schema-utils": "3.3.0",
2222
"semver": "6.3.1",
23-
"styled-jsx": "5.1.2",
2423
"tapable": "2.2.1",
2524
"terser-webpack-plugin": "5.3.10",
2625
"typescript": "5.3.3",

apps/3002-checkout/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"react-dom": "18.2.0",
2121
"schema-utils": "3.3.0",
2222
"semver": "6.3.1",
23-
"styled-jsx": "5.1.2",
2423
"tapable": "2.2.1",
2524
"terser-webpack-plugin": "5.3.10",
2625
"typescript": "5.3.3",

apps/node-host/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"dependencies": {
55
"@module-federation/node": "workspace:*",
6+
"@module-federation/enhanced": "workspace:*",
67
"@module-federation/runtime": "workspace:*"
78
}
89
}

apps/node-host/webpack.config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
const { composePlugins, withNx } = require('@nx/webpack');
2-
const { UniversalFederationPlugin } = require('@module-federation/node');
2+
const { ModuleFederationPlugin } = require('@module-federation/enhanced');
33

44
// Nx plugins for webpack.
55
module.exports = composePlugins(withNx(), async (config) => {
66
// Update the webpack config as needed here.
77
// e.g. `config.plugins.push(new MyPlugin())`
88
config.cache = false;
99
config.devtool = false;
10-
config.output.publicPath = 'auto';
10+
config.target = 'async-node';
11+
config.output.publicPath = '/testing';
12+
config.output.chunkFilename = '[id]-[chunkhash].js';
13+
config.optimization.chunkIds = 'named';
1114
await new Promise((r) => setTimeout(r, 400));
1215
config.module.rules.pop();
1316
config.plugins.push(
14-
new UniversalFederationPlugin({
15-
isServer: true,
17+
new ModuleFederationPlugin({
1618
name: 'node_host',
17-
runtimePlugins: [require.resolve('./runtimePlugin.ts')],
19+
dts: false,
20+
runtimePlugins: [
21+
require.resolve('@module-federation/node/runtimePlugin'),
22+
],
1823
remotes: {
1924
node_local_remote:
2025
'commonjs ../../node-local-remote/dist/remoteEntry.js',

apps/node-local-remote/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "node-local-remote",
33
"private": true,
44
"dependencies": {
5+
"@module-federation/enhanced": "workspace:*",
56
"@module-federation/node": "workspace:*"
67
}
78
}

apps/node-local-remote/webpack.config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@ const { registerPluginTSTranspiler } = require('nx/src/utils/nx-plugin.js');
22

33
registerPluginTSTranspiler();
44
const { composePlugins, withNx } = require('@nx/webpack');
5-
const { UniversalFederationPlugin } = require('@module-federation/node');
5+
const { ModuleFederationPlugin } = require('@module-federation/enhanced');
66
// Nx plugins for webpack.
77
module.exports = composePlugins(withNx(), (config) => {
88
config.output.publicPath = 'auto';
9-
config.target = 'node';
9+
config.target = 'async-node';
1010
config.devtool = false;
1111
config.cache = false;
12-
config.devServer.devMiddleware.writeToDisk = true;
12+
13+
if (config.devServer) {
14+
config.devServer.devMiddleware.writeToDisk = true;
15+
}
1316

1417
config.plugins.push(
15-
new UniversalFederationPlugin({
16-
isServer: true,
18+
new ModuleFederationPlugin({
1719
name: 'node-local-remote',
20+
dts: false,
21+
runtimePlugins: [
22+
require.resolve('@module-federation/node/runtimePlugin'),
23+
],
1824
library: { type: 'commonjs-module' },
1925
filename: 'remoteEntry.js',
2026
exposes: {
2127
'./test': './src/expose.js',
2228
},
23-
experiments: {},
2429
}),
2530
);
2631
return config;

0 commit comments

Comments
 (0)