Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Module Federation library type:'module' #6272

Closed
k4rl1 opened this issue Apr 17, 2024 · 11 comments
Closed

Support Module Federation library type:'module' #6272

k4rl1 opened this issue Apr 17, 2024 · 11 comments
Assignees

Comments

@k4rl1
Copy link

k4rl1 commented Apr 17, 2024

When I use

moduleFederation: { options: { name: 'template-rspack-react', library: { type: 'module' }, ...

when I build the application with 'rsbuild build' I get

JavaScript parsing error: 'import', and 'export' cannot be used outside of module code ╭─[4498:1] 4498 │ var __webpack_exports__ = __webpack_require__("581");var __webpack_exports__get = __webpack_exports__.get; 4499 │ var __webpack_exports__init = __webpack_exports__.init; 4500 │ export { __webpack_exports__get as get, __webpack_exports__init as init }; · ────── 4501 │ 4502 │ })()

which is in my opinion related to the webpack config property environment: {module: true} which does not work with rspack but works fine with webpack.

module.exports = { output: { environment: { module: true }, },

https://webpack.js.org/configuration/output/#outputenvironment

Thanks!

@ahabhgk
Copy link
Collaborator

ahabhgk commented Apr 26, 2024

Already supported

which is in my opinion related to the webpack config property environment: {module: true} which does not work with rspack but works fine with webpack.

What problem have you encountered? Would you provide a minimal reproduce?

Copy link
Contributor

Hello @k4rl1, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

@k4rl1
Copy link
Author

k4rl1 commented Apr 30, 2024

Will post a demo today

@k4rl1
Copy link
Author

k4rl1 commented Apr 30, 2024

Here is the demo: https://github.com/k4rl1/rspack-repro-mf-module-demo
npm run build:rsbuild tries to build it with rsbuild and fails
npm run build:webpack builds it with webpack and works

Adding:

 experiments: {
    outputModule: true,
  },

AND
environment: { module: true, dynamicImport: true }

like it is in the webpack config which is necessary to get it working in webpack does not do anything in the rspack config.

@ahabhgk
Copy link
Collaborator

ahabhgk commented Apr 30, 2024

Have you tried using the same configuration in rspack? It should work if you also add environment: { module: true, dynamicImport: true } in rspack

@k4rl1
Copy link
Author

k4rl1 commented Apr 30, 2024

Yes, this is what I mentioned above. It does not work in the rspack config but it works fine in webpack which is the reason a opened this issue.

@ahabhgk
Copy link
Collaborator

ahabhgk commented Apr 30, 2024

I see.. Rspack didn't extract the entry module out of the iife #6402, which cause the parsing error above, we will fix it in the next few days, thanks for report this and the reproduction you provided

@ahabhgk ahabhgk self-assigned this Apr 30, 2024
@k4rl1
Copy link
Author

k4rl1 commented Apr 30, 2024

Great to hear, thanks for the effort you put into it :) I will happily test it when it's done.

Copy link
Contributor

Since the issue was labeled with need reproduction, but no response in 14 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2024
@ahabhgk ahabhgk reopened this May 15, 2024
@ahabhgk
Copy link
Collaborator

ahabhgk commented May 15, 2024

Could you try the latest rsbuild, and add config.experiments.outputModule = true; in tools.rspack, rsbuild didn't enable it by default, and in the webpack.config.cjs it's enabled, that's why webpack build succeed but rsbuild failed

@ahabhgk ahabhgk closed this as completed May 15, 2024
@k4rl1
Copy link
Author

k4rl1 commented May 16, 2024

Ah thank you was not aware that it works like that. Thanks for your help :) Works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants