-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using externalHelpers causes webpack errors 'import' and 'export' may appear only with 'sourceType: module' #6728
Comments
Closing as this is not a bug of swc |
Little update on this - it actually affects all of those modules, but instead of errors during build it will lead to runtime errors. Because webpack in this case will consider that modules as esm and will ignore any
I agree that swc did what it told to do i.e. to generate esm code. The issue comes more from the different module ecosystems that should work together. But it makes swc actually unusable to generate optimized bundles as we can't change all the npm packages at once to make it work properly for esm build. I see that babel chose to be more flexible in that case to support real projects as it may affect any project that uses different npm packages. |
Why do you transpile packages in node_modules at first? |
It's very common that some packages use ES6 or higher version syntax in their output, it makes sense to me. |
It's not a bug anyway IMO, but it's fixed in recent versions |
If it's not a bug why is that fixed then? Or is it a bug that it is fixed and that behavior might be rolled back again in the future? I see that you pointed to the playground, but the link actually uses |
Thats not a bug. you can see the pr fix the polyfill in script not your issue. You set isModule true manually, so I think its right for swc to inject import You can set isModule unknown, let swc decide it is script or module |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
In my config swc is currently set up to output esm modules in order to let the webpack handle all the stuff with modules. And it mostly works well, but for some packages in node_modules I'm getting the next error:
There is no such issue for babel though.
I've made some digging to trace the error cause:
javascript/auto
to provide smart parsing that will dynamically figure out is it esm or commonjs. But some of the packages are explicitly marked withtype: "commonjs"
in their package.json and it get parsed in webpack more strictly leading to the error aboveInput code
Config
Playground link
https://play.swc.rs/?version=1.3.24&code=H4sIAAAAAAAAA0vOzysuUUgrVrBVKEotLM0sStVQSitW0rTm5eLlSq0oyC8qKdYrSQWqsVVILK7MS1bQ0FSwtVOorrUGALdsYEI7AAAA&config=H4sIAAAAAAAAA0WOSwrDMAxE76K1t%2B3CJ%2BimhxCuElz8Q1IgxvjutYNLdmI0b2YafMWBbVCQhXheUpPiCRa0FhLHvigYUBnShkGoG6BTiROGF4VCLGCVDxoe5J10kCSPgYSchRZkIPrktzoLXI6FSeR%2BYdrD39lHfsyfYwrt2nAFPqHfGYvz8l7G2d9%2Fo%2FC0EMwAAAA%3D
Expected behavior
Generate imports for helpers as it is implemented in babel - based on the sourceType of the module itself, not only bare config
Actual behavior
Generated imports for helpers are always in esm
Version
1.3.24
Additional context
The issue might be related
The text was updated successfully, but these errors were encountered: