Setting up Jest with ESM
Here are some different ways on how to set up Jest to support ES modules.
Here are some different ways on how to set up Jest to support ESM. This applies for Jest v25, Node v13, and Babel v7.
Node v14 and Jest v26 support ESM natively with the
--experimental-vm-modules flag. Install
cross-env 1, then add
NODE_OPTIONS to the scripts.test in package.json 2. See tne Jest documentation for more info (jest.io).
babel-jest (1). Configure Babel (2). We’ll use env.test here so not to interfere with your build process.
jest-esm-transformer - this is a preset configuration of Babel to support ESM transpilation.
As of March 2020, using
esm is currently not possible. Follow these threads for details.
buble-jest. Buble is an alternative to Babel. Note that as of 2021, this package hasn’t been updated since 2018.