Skip to content

Latest commit

History

History
17 lines (12 loc) 路 1.38 KB

ECMAScriptModules.md

File metadata and controls

17 lines (12 loc) 路 1.38 KB
id title original_id
version-26.0-ecmascript-modules
ECMAScript Modules
ecmascript-modules

Jest ships with experimental support for ECMAScript Modules (ESM).

Note that due to its experimental nature there are many bugs and missing features in Jest's implementation, both known and unknown. You should check out the tracking issue and the label on the issue tracker for the latest status.

Also note that the APIs Jest uses to implement ESM support is still considered experimental by Node (as of version 14.13.1).

With the warnings out of the way, this is how you activate ESM support in your tests.

  1. Ensure you either disable code transforms by passing transform: {} or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS).
  2. Execute node with --experimental-vm-modules, e.g. node --experimental-vm-modules node_modules/.bin/jest or NODE_OPTIONS=--experimental-vm-modules npx jest etc.
  3. Beyond that, we attempt to follow node's logic for activating "ESM mode" (such as looking at type in pakcgae.json or mjs files), see their docs for details