swc compatibility issues #398
Replies: 2 comments
-
@matthewjh points out two issues:
This is "breaking" because if SWC emits an import for a symbol that doesn't exist in the corresponding file, that will break downstream in bundling or loading the module via Node.
|
Beta Was this translation helpful? Give feedback.
-
ESM transpiled to CommonJS: When transpiling esm to cjs SWC tries to maintain the esm behaviour and restrictions, while tsc transpiles to a more lenient version more closely aligned with node cjs. For example, esm imports are readonly and can not be modified, traditionally cjs imports are writeable (the Source ts: export const FOO = "bar" SWC output: Object.defineProperty(exports, "FOO", {
enumerable: true,
get: function() {
return FOO;
}
});
var FOO = "bar" TypeScript output: exports.FOO = void 0;
var FOO = "bar"
exports.FOO = FOO; |
Beta Was this translation helpful? Give feedback.
-
SWC is a VERY fast transpiler, allowing TypeScript to be converted to JavaScript in milliseconds and at large scale.
This discussion can collect pointers to the problems we know of when using
ts_project(transpiler = swc)
along with known workarounds.Beta Was this translation helpful? Give feedback.
All reactions