Skip to content

Commit 3a8414a

Browse files
authored
fix(nextjs-antd): Fixed module federation dependencies (#2689)
* Fixed nextjs-antd * fix(nextjs-antd): fixed README * Update index.js * Update index.js
1 parent ca6b1cf commit 3a8414a

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

nextjs-antd/3000-home/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"start": "next start -p 3000"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "^5.1.2",
12-
"antd": "^4.22.3",
11+
"@module-federation/nextjs-mf": "5.1.2",
12+
"antd": "4.22.3",
1313
"lodash": "4.17.21",
1414
"next": "12.2.2",
15-
"next-compose-plugins": "^2.2.1",
15+
"next-compose-plugins": "2.2.1",
1616
"nextjs-shared": "link:../shared",
1717
"react": "18.1.0",
1818
"react-dom": "18.1.0",
1919
"webpack": "5.72.1",
20-
"webpack-merge": "^5.8.0"
20+
"webpack-merge": "5.8.0"
2121
}
2222
}

nextjs-antd/3001-shop/next.config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const NextFederationPlugin = require('@module-federation/nextjs-mf');
22

33
module.exports = {
44
webpack(config, options) {
5-
if (!options.isServer) {
5+
const { webpack } = options;
6+
Object.assign(config.experiments, { topLevelAwait: true });
7+
if (!options.isServer) {
8+
//config.cache=false
69
config.plugins.push(
710
new NextFederationPlugin({
811
name: 'shop',
@@ -27,10 +30,12 @@ module.exports = {
2730
'./pages/_menu': './pages/_menu.js',
2831
'./pages-map': './pages-map.js',
2932
},
30-
extraOptions: {
31-
enableImageLoaderFix: true,
32-
enableUrlLoaderFix: true,
33-
},
33+
shared: {},
34+
extraOptions: {
35+
exposePages: true,
36+
enableImageLoaderFix: true,
37+
enableUrlLoaderFix: true,
38+
},
3439
}),
3540
);
3641
}

nextjs-antd/3001-shop/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "rm -rf .next && next dev -p 3001",
6+
"dev": "next dev -p 3001",
77
"build": "next build",
88
"start": "next start -p 3001"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "^5.1.2",
12-
"antd": "^4.22.3",
11+
"@module-federation/nextjs-mf": "5.1.2",
12+
"antd": "4.22.3",
1313
"lodash": "4.17.21",
1414
"next": "12.2.2",
15-
"next-compose-plugins": "^2.2.1",
15+
"next-compose-plugins": "2.2.1",
1616
"nextjs-shared": "link:../shared",
1717
"react": "18.1.0",
1818
"react-dom": "18.1.0",
1919
"webpack": "5.72.1",
20-
"webpack-merge": "^5.8.0"
20+
"webpack-merge": "5.8.0"
2121
}
2222
}

nextjs-antd/3002-checkout/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"start": "next start -p 3002"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "^5.1.2",
11+
"@module-federation/nextjs-mf": "5.1.2",
1212
"antd": "4.20.0",
1313
"lodash": "4.17.21",
1414
"next": "12.2.2",
15-
"next-compose-plugins": "^2.2.1",
15+
"next-compose-plugins": "2.2.1",
1616
"nextjs-shared": "link:../shared",
1717
"react": "18.1.0",
1818
"react-dom": "18.1.0",
1919
"webpack": "5.72.1",
20-
"webpack-merge": "^5.8.0"
20+
"webpack-merge": "5.8.0"
2121
}
2222
}

nextjs-antd/README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# Next.js with Module Federation
22

3-
Module Federation in Next.js depends on <a href="https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-mf">@module-federation/nextjs-mf</a> It will not work unless you have access to this plugin, which is not free.
4-
5-
Due to the effort to support Next.js and funding constraints, I have moved the plugin to a paid model.
6-
73
NOTE: There seems to be a problem with css-in-js sharing between federated modules. This is likely due to some internal module not being shared as a singleton. PR is welcome
84

95
## Getting Started
106

11-
1. run `npm install @module-federation/nextjs-mf --registry https://r.privjs.com` with npm 7 (yarn probbably better) or install it directly in each folder/app, note the plugin is not free.
7+
1. run `yarn install` with npm 7 (yarn probbably better).
128
2. run `yarn start` and browse to `http://localhost:3001`
139

1410
# We are available to consult
@@ -17,8 +13,6 @@ Looking for SSR over `fetch()` or architecture support and designs for module fe
1713

1814
Contact me <a href="mailto:zackary.l.jackson@gmail.com">zackary.l.jackson@gmail.com</a> or <a href="https://twitter.com/scriptedalchemy">@ScriptedAlchemy</a> on Twitter
1915

20-
All solutions for next.js currently require a paid access or paid plugin
21-
2216
## Context
2317

2418
We have three next.js applications
@@ -52,7 +46,7 @@ const config = {
5246
};
5347
```
5448

55-
However, in the case of Next.js - you need to use <a href="https://app.privjs.com/buy/packageDetail?pkg=@module-federation/nextjs-mf">@module-federation/nextjs-mf</a>
49+
However, in the case of Next.js - you need to use @module-federation/nextjs-mf
5650

5751
## Reference Points
5852

nextjs-antd/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"scripts": {
1212
"clear": "cd 3000-home && rm -rf node_modules && rm -rf .next && cd ../3001-shop && rm -rf node_modules && rm -rf .next && cd ../3002-checkout && rm -rf node_modules && rm -rf .next",
1313
"start": "yarn dev",
14-
"dev": "yarn install && concurrently \"cd 3000-home; npm run dev\" \"cd 3001-shop; npm run dev\" \"cd 3002-checkout; npm run dev\"",
15-
"build": "concurrently \"cd 3000-home; npm run build\" \"cd 3001-shop; npm run build\" \"cd 3002-checkout; npm run build\"",
16-
"serve": "concurrently \"cd 3000-home; npm run start\" \"cd 3001-shop; npm run start\" \"cd 3002-checkout; npm run start\""
14+
"dev": "concurrently \"yarn --cwd 3000-home dev\" \"yarn --cwd 3001-shop dev\" \"yarn --cwd 3002-checkout dev\"",
15+
"build": "concurrently \"yarn --cwd 3000-home build\" \"yarn --cwd 3001-shop build\" \"yarn --cwd 3002-checkout build\"",
16+
"serve": "concurrently \"yarn --cwd 3000-home start\" \"yarn --cwd 3001-shop start\" \"yarn --cwd 3002-checkout start\""
1717
},
1818
"dependencies": {
1919
"concurrently": "^7.0.0",
20+
"@module-federation/nextjs-mf": "6.0.5",
21+
"webpack": "5.72.1",
2022
"cpx": "1.5.0"
2123
}
2224
}

nextjs-antd/shared/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"module": "./index.js",
66
"types": "./index.d.ts",
77
"dependencies": {
8-
"feather-route-matcher": "^4.0.0"
8+
"@module-federation/nextjs-mf": "5.1.2",
9+
"feather-route-matcher": "4.0.0"
910
}
1011
}

0 commit comments

Comments
 (0)