-
-
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
A commonjs module could be wrongly marked with __esModule: true
while enabling external helpers
#6500
Comments
The swc input has only module and script, which are distinguished by import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
// sibling-module.js is a CommonJS module.
const siblingModule = require('./sibling-module'); https://nodejs.org/api/module.html#modulecreaterequirefilename |
Do you imply another way to introduce swc helpers? For example, use |
That's one way to solve it. |
The use case is when you transpile react.cjs.js to downgrade some syntax, the output will be marked as an ES module. |
what abut check ModuleDecl's span before set has_module_decl = true? |
Any update or workaround for this issue? External helpers are very useful for reducing the bundle size, but this issue prevents their usage. |
Describe the bug
The input code is commonjs. If SWC triggers any helpers in transpiling or other processes, which will inject
import ... from '@swc/...'
statements, the commonjs visitor will detect these import statements and mark it with__esModule: true
. But the original module is actually a commonjs module.Input code
Config
Playground link
https://play.swc.rs/?version=1.3.19&code=H4sIAAAAAAAAA0vOzysuUUhUsFUoSi0szSxK1VDX00%2FLz1fX5EoGSwHZQMnE4sq8ZAUNTQVbO4XqWgCakFypNQAAAA%3D%3D&config=H4sIAAAAAAAAA0WOSwrDMAxE76J1tt3kBN30EMKVUwf%2FkBRICL57JRKINx48jzc%2BYZUA8wkdWYg9yVEVd5iBQkEJnLrCZJg9RcxCYwJFXkgdkZd1uTWhu52gpJri4abQSmcSeSqsS6bHQ7sSV8xvyp3YOOXNMGWsEhsXlzBh0CtEk%2F0sDjsma9%2FNZSfo0e32udLqKjCeT9zDST437QvjD6ne0KH2AAAA
Expected behavior
Actual behavior
Version
1.3.19
Additional context
No response
The text was updated successfully, but these errors were encountered: