CoffeeScript default CommonJS module output incompatible with ES‑module bundlers
0 reputation · 17 Mar 2026, 05:14 UTC
CoffeeScript default CommonJS module output incompatible with ES‑module bundlers
The CoffeeScript compiler (v1.x) emits CommonJS require and module.exports statements by default. Production builds that bundle the generated JavaScript with tools configured for ES modules (e.g., Webpack, Rollup) often encounter runtime errors such as Uncaught ReferenceError: module is not defined because the bundler expects import / export syntax.
Currently, the compiler offers no flag to change the emitted module system; the --compile and --output options only control file paths. This lack of a module‑format switch is an unresolved design decision: should a --module or --es6 flag be added, or should CoffeeScript rely on a separate transpilation step?
Given this situation, developers need to decide how to integrate CoffeeScript into modern bundling workflows without adding extra build complexity.
Key questions
- Should the CoffeeScript project introduce a compiler flag to emit ES module syntax directly?
- What are the trade‑offs of adding such a flag versus continuing to rely on post‑processing with Babel or manual edits?
- How might future CoffeeScript releases impact existing build scripts that depend on the current CommonJS default?