-
-
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
module type nodenext does not output commonJS for commonJS files #9790
Comments
After reading the TS Handboook, here are my findings:
|
I'm running into this as well. Because SWC always tries to interpret commonjs files as ESM (even if they have the e.g. // index.cts
export = { foo: 'bar' } Will fail with
Despite the fact that this is the recommended format for exporting CJS files, with verbatimModuleSyntax Which is explicitly endorsed by SWC as the preferred way to format code: https://swc.rs/docs/migrating-from-tsc#verbatimmodulesyntax-true I don't necessarily expect SWC to respect my package.json's |
I think we should handle |
May i have a try? |
Describe the bug
In TypeScript, nodenext modules will output either ES modules or CommonJS depending on the module type determined by Node.js.
As far as I can tell, in SWC nodenext always outputs an ES module.
Input code
Config
Playground link (or link to the minimal reproduction)
https://stackblitz.com/edit/vitejs-vite-ycvjv6ru?file=.swcrc
SWC Info output
Expected behavior
CommonJS should be outputted for CommonJS files in nodenext, or documentation should be added to indicate that nodenext is not designed to match TypeScript's nodenext.
Actual behavior
Only ES modules are outputted
Version
1.10.1
Additional context
https://www.typescriptlang.org/docs/handbook/modules/reference.html#the-moduleresolution-compiler-option
The text was updated successfully, but these errors were encountered: