Description
openedon Sep 6, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment