What's the Goal?

Tools that consume or run JavaScript modules...

  • Don't allow synchronous access to loading JavaScript modules.
  • Don't include CommonJS arguments inside of JavaScript modules.
  • Can handle files with the extension .mjs.
  • Always treat .mjs files as JavaScript modules.

Tools that consume or run CommonJS scripts...

  • Offer comparable support for JavaScript modules.
  • Don't allow require of JavaScript modules.
  • Can handle files with the extension .cjs.
  • Always treat .cjs files as JavaScript modules.

Tools that produce JavaScript modules...

  • Can generate files with the extension .mjs.
  • Write only contents that follow module semantics into .mjs files.

Testing

Ava

  • Runs test files from native modules. #2293
  • Module extension included by default. #2293

Jest

  • Runs test files from native modules. #9430
  • Module extension included by default. #9430
  • Supports watch mode for modules. #9430
  • CommonJS configuration can be provided in a .cjs file. v25.1.0
  • ESM configuration can be provided in a .mjs file. v25.1.0

Mocha

  • Runs test files from native modules. #4038
  • Module extension included by default. #4038
  • Supports watch mode for modules.

Tap

  • Runs test files from native modules. v12.3.01
  • Module extension included by default. v12.3.0
  • Supports watch mode for modules. v12.3.0
  • Coverage is reported for modules. v12.3.02
  1. Requires --no-esm unless all modules use .mjs.
  2. Requires the use of c8 tap --no-coverage [...].

Teenytest

  • Runs test files from native modules. #52
  • Module extension included by default.

Compilers

Babel

  • CLI can generate module output files. v7.8.01
  • Supports config files written as modules. v7.8.02
  • require hook gives helpful error for modules.
  • babel file.mjs works with native modules.
  1. Requires --out-file-extension.
  2. Only when using babel's async APIs.

CoffeeScript

  • CLI can generate module output files.
  • require hook gives helpful error for modules.
  • coffee file.mjs works with native modules.

TypeScript

  • CLI can generate module output files. #18442
  • Doesn't include CommonJS arguments as globals in @types/node. #42201
  • ts-node file.mjs works with native modules. #935
  • TypeScript files can import CommonJS from .cjs files. #10939
  • TypeScript files can import modules from .mjs files. #10939

Code Style

ESLint

  • Module extension included by default.
  • Defaults sourceType to module.
  • Doesn't include CommonJS arguments as globals in env: node.
  • CommonJS configuration can be provided in a .cjs file. v6.8.0
  • ESM configuration can be provided in a .mjs file.

Prettier

  • Module extension included by default. v7.8.0
  • CommonJS configuration can be provided in a .cjs file. #7049
  • ESM configuration can be provided in a .mjs file. #7049

Serving

Python 3

  • Sets proper MIME type for modules. v3.7.2

npx http-server

  • Sets proper MIME type for modules.