首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应主机和NextJS远程应用程序示例/配置模块联合会

反应主机和NextJS远程应用程序示例/配置模块联合会
EN

Stack Overflow用户
提问于 2022-04-24 11:44:20
回答 1查看 983关注 0票数 1

我没有找到一个react主机和nextjs远程应用程序的例子,我的主机正在使用一个react远程应用程序,现在我正在尝试添加一个nextjs远程应用程序,它不起作用:

  • 港口:
代码语言:javascript
复制
- Host `3000`
- React remote `3001`
- NextJS Remote `3002`
  • 在我的主机react应用程序中,我有以下内容,在webpack.config.js文件中
代码语言:javascript
复制
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文件

代码语言:javascript
复制
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中,我试图使用以下远程组件
代码语言:javascript
复制
import RemoteNav from 'remote_react/Nav'; // <- Working 
import ExposedComponent from 'remote_nextjs/ExposedComponent'; // <- Not working

我从js.js得到它的404错误

谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-11-01 09:35:05

参考https://webpack.js.org/guides/public-path/,在远程应用程序的webpack配置中,设置publicPath将修复路径问题。

代码语言:javascript
复制
  export default {
    output: {
      publicPath: 'auto',
    },
    plugins: [...],
    ...
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71988055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档