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

[Bug]: hmr runtime was not transformed as expected #1804

Closed
xc2 opened this issue Mar 12, 2024 · 3 comments · Fixed by #1825
Closed

[Bug]: hmr runtime was not transformed as expected #1804

xc2 opened this issue Mar 12, 2024 · 3 comments · Fixed by #1825
Assignees
Labels
🐞 bug Something isn't working

Comments

@xc2
Copy link
Collaborator

xc2 commented Mar 12, 2024

Details

Original post: https://discord.com/channels/977448667919286283/1215728156984610876

image

{
buildType: 'bundle',
format: 'esm',
target: 'es5',
dts: false,
input: {
hmr: 'src/client/hmr/index.ts',
},
outDir: './dist/client',
autoExtension: true,
// bundle shared deps when used in client
autoExternal: false,
},

the hmr runtime appears to be meant to target es5 but module-tools will strip it as esbuild don't support es5. This results in the hmr runtime kept untransformed.

https://github.com/web-infra-dev/modern.js/blob/2e7585862237e957054ccfa37632c2a34ce6c881/packages/solutions/module-tools/src/builder/esbuild/index.ts?plain=1#L153

we have to update the target to es6 atm as it's the minimium target we can have with esbuild without an additional plugin.

Reproduce link

https://www.npmjs.com/package/@rsbuild/core?activeTab=code

@rsbuild/core/dist/client/hmr.mjs

@chenjiahan
Copy link
Member

Thanks! It is still necessary to transform client code to es5, as some apps may still need to be compatible with legacy browsers.

Actually, this is a bug of Modern.js Module, it should enable SWC transform when target is 'es5'. I have submit a PR to fix this: web-infra-dev/modern.js#5527

@wChenonly
Copy link
Contributor

I also encountered this problem today. Through investigation just now, I found that the target in baseBuildConfig in the modern.base.config.ts file is es2020.
image

@chenjiahan
Copy link
Member

I found that the target in baseBuildConfig in the modern.base.config.ts file is es2020.

Yeah, the es2020 is for Node.js target, and client code should be transformed to es5 for compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants