Closed mihuartuanr closed 7 months ago
"No ModuleFederationPlugin(s) found" is a false flag, not a real error. Leftover issue from years old plugin that still runs data correlation deeper down in next's implementation
This issue should disappear when i rewrite that part in the future
"No ModuleFederationPlugin(s) found" is a false flag, not a real error. Leftover issue from years old plugin that still runs data correlation deeper down in next's implementation
This issue should disappear when i rewrite that part in the future
module-federation can't work in next14, so what i should do to solve it current?
https://github.com/module-federation/universe/pull/2149 Found ruleset issue
@module-federation/nextjs-mf": "^8.1.7",
update to "^8.2.0"
,new issue occur.
terminal console:
https://nextjs.org/docs/messages/module-not-found
⨯ ./src/app/page.tsx:1:0
Module not found: Can't resolve 'remoteApp/RemoteButton'
chrome devtool console:
Uncaught TypeError: _Users_Workplaces_myapp_node_modules_module_federation_nextjs_mf_dist_src_plugins_container_runtimePlugin_js__WEBPACK_IMPORTED_MODULE_1__ is not a function
is federation applied server side too? if not then you need to use resolve alias false for remote imports on server config
now i change federation applied in client side, terminal
has no error, but chrome devtool still print error.
devtool prints new message :
Uncaught TypeError: _Users_Workplaces_myapp_node_modules_module_federation_nextjs_mf_dist_src_plugins_container_runtimePlugin_js__WEBPACK_IMPORTED_MODULE_1__ is not a function at eval (entry.df7c6e8affba247d606231c558befe8a.js:10:3)
Uncaught TypeError: _Users_Workplaces_myapp_node_modules_module_federation_nextjs_mf_dist_src_plugins_container_runtimePlugin_js__WEBPACK_IMPORTED_MODULE_2__ is not a function (entry.df7c6e8affba247d606231c558befe8a.js:32)
GET http://localhost:3004/autostatic/chunks/app-pages-internals.js net::ERR_ABORTED 404 (Not Found) localhost/:1
GET http://localhost:3004/autostatic/chunks/app/page.js net::ERR_ABORTED 404 (Not Found)
entry.df7c6e8affba247d606231c558befe8a.js:32
constains:
import federation from '/Users/Workplaces/myapp/node_modules/@module-federation/webpack-bundler-runtime/dist/index.cjs.js';
import plugin_0 from '/Users/Workplaces/myapp/node_modules/@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js';
__webpack_require__.federation = {...federation,...__webpack_require__.federation};
if(!__webpack_require__.federation.instance){
__webpack_require__.federation.initOptions.plugins = ([
plugin_0(),
])
__webpack_require__.federation.instance = __webpack_require__.federation.runtime.init(__webpack_require__.federation.initOptions);
if(__webpack_require__.federation.attachShareScopeMap){
__webpack_require__.federation.attachShareScopeMap(__webpack_require__)
}
if(__webpack_require__.federation.installInitialConsumes){
__webpack_require__.federation.installInitialConsumes()
}
}```
nest.config.js
contains:
webpack(config, options) {
// if (options.isServer) {
// config.resolve.alias = {
// ...config.resolve.alias,
// 'docbtn/RemoteButton': false
// };
// }
config.output = {
...config.output,
environment: {
asyncFunction: true
}
};
if (!options.isServer) {
config.plugins.push(
new NextFederationPlugin({
name: 'hostApp',
remotes: {
docbtn: 'remoteApp@http://localhost:3002/assets/remoteEntry.js'
// docbtn: `promise import("remoteApp@http://localhost:3000/assets/remoteEntry.js")`
},
filename: 'remoteEntry.js'
})
);
}
return config;
},
consumer is:
'use client';
import React from 'react';
import { lazy, useEffect, useState } from 'react';
export default function Home() {
const [Component, setComponent] = useState<React.FunctionComponent | null>(
null
);
useEffect(() => {
if (typeof window !== 'undefined') {
setComponent(lazy(() => import('docbtn/RemoteButton')));
}
}, []);
return (
<main>
123213213
{Component && <Component />}
35435435
</main>
);
}
@mihuartuanr your using app router, app router is not supported
Thanks, app router is used indeed.
yeah i just saw the example had app router in it, switched it back to pages and all seems good
ok. still expect follow-up support for app router.
Probably will take a long time. Next may drop webpack support before I can find a hack for next. We have rsc working elsewhere. But next is the worst imaginable thing to pair with MFP.
Maybe in 2025
'use client';
import { importRemote } from '@module-federation/utilities';
import { lazy, useEffect, useState } from 'react';
const RemoteService = () => {
const [Module, setModule] = useState<any>(null);
useEffect(() => {
importRemote({
url: 'http://127.0.0.1:3000',
remoteEntryFileName: 'remoteEntry.js',
scope: 'remoteApp',
module: 'RemoteButton'
}).then((res) => {
// const { Button } =res;
setModule(res);
console.log('-------importRemote------', res);
});
}, []);
// const Bar = lazy(() =>
// importRemote({
// url: 'http://localhost:3000',
// remoteEntryFileName: 'remoteEntry.js',
// scope: 'remoteApp',
// module: 'RemoteButton',
// esm: true
// })
// );
// console.log('-------------lazy-----------', Bar);
return (
<>
{Module && <Module.default></Module.default>}
</>
);
};
it works.
'use client'; import { importRemote } from '@module-federation/utilities'; import { lazy, useEffect, useState } from 'react'; const RemoteService = () => { const [Module, setModule] = useState<any>(null); useEffect(() => { importRemote({ url: 'http://127.0.0.1:3000', remoteEntryFileName: 'remoteEntry.js', scope: 'remoteApp', module: 'RemoteButton' }).then((res) => { // const { Button } =res; setModule(res); console.log('-------importRemote------', res); }); }, []); // const Bar = lazy(() => // importRemote({ // url: 'http://localhost:3000', // remoteEntryFileName: 'remoteEntry.js', // scope: 'remoteApp', // module: 'RemoteButton', // esm: true // }) // ); // console.log('-------------lazy-----------', Bar); return ( <> {Module && <Module.default></Module.default>} </> ); };
it works.
i want to know the feasibility that @module-federation/nextjs-mf fast to support app router by using '@module-federation/utilities'
Not with utilities. You can try using module-federation/runtime. If anything that might work.
Nextjs-MF will most likely never support app router tho. Vercel is building proprietary version of federation for rsc and next. No chance my stuff will work with build plug-in. Again maybe if you use federation run-time bit I have not tried this. If it works please report back.
Current:
npm run dev
occur errori has checked examples at least 3ds in https://github.com/module-federation/module-federation-examples/blob/master/nextjs-react/host-app/package.json.
Expect:
No ModuleFederationPlugin(s) found.
nextjs host app
package.json
:next.config.js
consumer
react webpack remote app