TypeError:withModuleFederation不是函数-NEXTJS ModuleFederation
我在 nextjs 中使用Micro-Frontend。 wen我在next.config.js中启动服务器 typeError:withModuleFederation不是函数
我尝试了 @module-federation/nextjs-mf的最新版本,但是在此中,我会得到版本不匹配错误。
有任何建议或解决方案吗?
next.config.js content
const {
withModuleFederation,
MergeRuntime,
} = require("@module-federation/nextjs-mf");
const path = require("path");
module.exports = {
webpack: (config, options) => {
const { buildId, dev, isServer, defaultLoaders, webpack } = options;
const mfConf = {
name: "test1",
library: { type: config.output.libraryTarget, name: "test1" },
filename: "static/runtime/remoteEntry.js",
remotes: {},
exposes: {
"./nav": "./components/nav",
},
shared: [],
};
withModuleFederation(config, options, mfConf);
config.plugins.push(new MergeRuntime());
if (!isServer) {
config.output.publicPath = "http://localhost:3000/_next/";
}
return config;
},
};
package.json content
{
"name": "charts",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"resolutions": {
"webpack": "5.1.3"
},
"dependencies": {
"@module-federation/nextjs-mf": "^2.3.1",
"next": "12.1.6",
"react": "18.1.0",
"react-dom": "18.1.0"
},
"devDependencies": {
"@types/node": "^17.0.40",
"@types/react": "^18.0.12",
"eslint": "8.17.0",
"eslint-config-next": "12.1.6",
"typescript": "^4.7.3"
}
}
I'm using micro-frontend in nextjs.
Wen i start the server, in the next.config.js am gettingTypeError: withModuleFederation is not a function
I tried the latest version of @module-federation/nextjs-mf but in this I'm getting version mismatch error.
any suggestion or solution ??
next.config.js content
const {
withModuleFederation,
MergeRuntime,
} = require("@module-federation/nextjs-mf");
const path = require("path");
module.exports = {
webpack: (config, options) => {
const { buildId, dev, isServer, defaultLoaders, webpack } = options;
const mfConf = {
name: "test1",
library: { type: config.output.libraryTarget, name: "test1" },
filename: "static/runtime/remoteEntry.js",
remotes: {},
exposes: {
"./nav": "./components/nav",
},
shared: [],
};
withModuleFederation(config, options, mfConf);
config.plugins.push(new MergeRuntime());
if (!isServer) {
config.output.publicPath = "http://localhost:3000/_next/";
}
return config;
},
};
package.json content
{
"name": "charts",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"resolutions": {
"webpack": "5.1.3"
},
"dependencies": {
"@module-federation/nextjs-mf": "^2.3.1",
"next": "12.1.6",
"react": "18.1.0",
"react-dom": "18.1.0"
},
"devDependencies": {
"@types/node": "^17.0.40",
"@types/react": "^18.0.12",
"eslint": "8.17.0",
"eslint-config-next": "12.1.6",
"typescript": "^4.7.3"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@module-feDeration/nextjs-mf 不再免费,如果需要从
模块 - 芬德/nextjs-mf
@module-federation/nextjs-mf is no longer free, if its required need to purchase from
module-federation/nextjs-mf