jest: configuring for typescript and esm

2021-12-06

 | 

~1 min read

 | 

90 words

A natural follow up to Configuring Jest for Typescript with ts-jest, this Jest configuration write up is about configuring Jest to use native EcmaScript modules (ESM):

There are three steps:

  1. Update tsconfig.json
  2. Update jest.config.js
  3. Update package.json
tsconfig.json
{
  "target": "esnext",
  "module": "esnext"
}
jest.config.js
export default {
  globals: {
    "ts-jest": {
      useESM: true,
    },
  },
}
package.json
{
  "scripts": {
    "tdd": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --watch"
  }
}

Kent C Dodds has an example repo and Rico Sta. Cruz has written other options too.


Related Posts
  • Jest: How to configure Jest for testing Javascript applications


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!