Modules are how you organize code into self-contained chunks that you can reuse in different codebases and import as necessary. JavaScript didn’t have a standard module system until ECMAScript 2015 (with support for https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/ arriving in major browsers by 2018).

By default, Node.js treats the JavaScript code you import as CommonJS modules, for backward compatibility. That means developers who think they’re writing ES modules actually aren’t, Palmer warned, meaning they don’t get access to ES modules features like the new top-level await coming in https://thenewstack.io/javascript-forecast-whats-ahead-for-ecmascript-2022/.

Supporting developers through the transition to ES modules has been “an ongoing pain point,” explained https://twitter.com/drosenwasser, senior program manager for TypeScript at Microsoft.

Related Articles