我没有找到一个react主机和nextjs远程应用程序的例子,我的主机正在使用一个react远程应用程序,现在我正在尝试添加一个nextjs远程应用程序,它不起作用:
- Host `3000`
- React remote `3001`
- NextJS Remote `3002`webpack.config.js文件中plugins: [
new ModuleFederationPlugin({
name: 'react_container',
filename: 'remoteEntry.js',
remotes: {
remote_react: 'remote_react@http://localhost:3001/remoteEntry.js', // <- This is working
remote_nextjs: 'remote_nextjs@http://localhost:3002/_next/static/chunks/remoteEntry.js', // <- Not working :-(
},
exposes: {
'./react': 'react',
'./react-dom': 'react-dom',
},
shared: {
},
}),和远程nextjs应用程序中的next.config.js文件
const { withFederatedSidecar } = require("@module-federation/nextjs-mf");
module.exports = withFederatedSidecar({
name: "remote_nextjs",
filename: "static/chunks/remoteEntry.js",
exposes: {
"./ExposedComponent": "./components/ExposedComponent",
},
shared: {
},
})({
// your original next.config.js export
});App.jsx中,我试图使用以下远程组件import RemoteNav from 'remote_react/Nav'; // <- Working
import ExposedComponent from 'remote_nextjs/ExposedComponent'; // <- Not working我从js.js得到它的404错误

谢谢
发布于 2022-11-01 09:35:05
参考https://webpack.js.org/guides/public-path/,在远程应用程序的webpack配置中,设置publicPath将修复路径问题。
export default {
output: {
publicPath: 'auto',
},
plugins: [...],
...
}https://stackoverflow.com/questions/71988055
复制相似问题