Bug Report
My project is set to emit ESNext modules. I have a variety of TS files, but I also have a single .cjs file, which needs to remain CommonJS to try and require legacy packages.
My input looks like this:
module.exports = {
tryRequire(modulePath) {
return require(modulePath);
},
};
I expect the output I get from TypeScript 4.7.4:
module.exports = {
tryRequire(modulePath) {
return require(modulePath);
},
};
When I upgrade to TypeScript 4.8.2, it now emits an extra export {} at the end of the .cjs file:
module.exports = {
tryRequire(modulePath) {
return require(modulePath);
},
};
export {}
This causes Node to fail parsing the .cjs file because export does not exist in the .cjs context.
🕗 Version & Regression Information
Worked in 4.7.4, broken in 4.8.2, also broken in current nightly (4.9.0-dev.20220905).
Repro here
https://github.com/dzearing/ts-repro-cjs
Bug Report
My project is set to emit ESNext modules. I have a variety of TS files, but I also have a single
.cjsfile, which needs to remain CommonJS to try and require legacy packages.My input looks like this:
I expect the output I get from TypeScript 4.7.4:
When I upgrade to TypeScript 4.8.2, it now emits an extra
export {}at the end of the .cjs file:This causes Node to fail parsing the
.cjsfile becauseexportdoes not exist in the .cjs context.🕗 Version & Regression Information
Worked in 4.7.4, broken in 4.8.2, also broken in current nightly (4.9.0-dev.20220905).
Repro here
https://github.com/dzearing/ts-repro-cjs