-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 detection treats typescript import ... = require as ES module syntax #54514
Comments
This syntax is not supported by node without some transformation. |
I don't see why this would be different than import fs = require("fs");
export = expr;
// Transforms into
const fs = require("fs");
module.exports = expr; |
It looks like SWC is auto-adding AFAIK that feature was added to workaround an issue with downstream processing by webpack. Given the only consumer of the emitted JS here is the Node runtime, it has no use for this generated syntax, so we should probably just pass a flag to SWC to disable that addition. It's one of the existing (but lesser known) SWC transform options and I can't find the name just now. |
cc @magic-akari for visibility There's It exists for the exact reason - Deno did not need |
Is this a bug in SWC? Previously, in SWC, subsequent processing would either convert to CJS, removing We didn't have a direct use case for TypeScript pass before, so we overlooked this intermediate outcome. |
**Related issue:** - nodejs/node#54514
This is a legit “aha” moment |
@marco-ippolito will amaro need to bump its swc version? |
No, we manually set the flag to remove |
PR-URL: #54517 Fixes: #54514 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
PR-URL: #54517 Fixes: #54514 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
PR-URL: nodejs#54517 Fixes: nodejs#54514 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
Version
v22.7.0
Platform
Subsystem
module
What steps will reproduce the bug?
Create a
.cts
file with the following contents:and run it with
node --experimental-transform-types ./example.cts
.How often does it reproduce? Is there a required condition?
This happens consistently.
What is the expected behavior? Why is that the expected behavior?
This should execute as a CommonJS module.
Despite appearances
import ... = require(...)
is specifically for CommonJS modules (so that CommonJS modules can also import and export types, not just values).What do you see instead?
The code is incorrectly transformed to have ES module syntax and throws an error at runtime:
Additional information
No response
The text was updated successfully, but these errors were encountered: