You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.ts files whose only imports and exports are type-only run as ES modules, without require or module #909
While investigating #905 the LLM stated it found another tangential bug. However, one of the impacted tests marked the logic as intentional, so could be a false positive.
Versions:oxc-project/oxc-node main (ffa98c1), @oxc-node/core 1.0.1, Node.js v26.12.1, linux-x64
Expected:ok string. Type erasure removes the import type, and nothing else in the file is module syntax, so Node.js' own type stripping (node ./entry.ts) runs it as CommonJS and prints ok string. tsc with module: nodenext emits CommonJS for it too.
Actual:
ReferenceError: require is not defined in ES module scope, you can use import instead
The same happens when the file is require()d from a .cjs file or imported from an .mts file, and with every declaration that type erasure removes whole: export type { … } (with or without from), export type * from, export type X = …, export interface, export default interface and export declare ….
Error: Failed to transform …/counter.ts:
! TS(1203): Export assignment cannot be used when targeting ECMAScript modules.
When it is require()d, the error is ReferenceError: module is not defined in ES module scope. tsc compiles it to module.exports = { platform };.
Cause
oxc's parser resolves a file with a type-only import/export to a module, and parsed_as_esm (src/lib.rs) counts those declarations as module syntax, so the load hook reports the file as an ES module. On the require() path, the TypeScript transform appends an empty export {} when it erases the file's last import/export, so the output is an ES module there as well.
Activity
fix(core): keep CommonJS files whose only imports and exports are typ…
fix(core): keep CommonJS files whose only imports and exports are typ…
fix(core): run files whose only imports and exports are type-only as
fix(core): don't count type-only imports and exports as ES module syn…
fix(core): run files whose only imports and exports are type-only as …