Skip to main content
Version: 27.0

ESM Support

To use ts-jest with ESM support, you'll first need to check ESM Jest documentation.

ts-jest supports ESM via a config option useESM in combination with jest config option extensionsToTreatAsEsm.

There are also 3 presets to work with ESM.

Examples#

Manual configuration#

// jest.config.jsmodule.exports = {  // [...]  extensionsToTreatAsEsm: ['.ts'],  globals: {    'ts-jest': {      useESM: true,    },  },  moduleNameMapper: {    '^(\\.{1,2}/.*)\\.js$': '$1',  },}
// OR package.json{  // [...]  "jest": {    "extensionsToTreatAsEsm": [".ts"],    "globals": {      "ts-jest": {        "useESM": true      }    },    "moduleNameMapper": {      "^(\\.{1,2}/.*)\\.js$": "$1"    }  }}

Use ESM presets#

// jest.config.jsmodule.exports = {  // [...]  preset: 'ts-jest/presets/default-esm', // or other ESM presets  globals: {    'ts-jest': {      useESM: true,    },  },  moduleNameMapper: {    '^(\\.{1,2}/.*)\\.js$': '$1',  },}
// OR package.json{  // [...]  "jest": {    "preset": "ts-jest/presets/default-esm", // or other ESM presets,    "globals": {      "ts-jest": {        "useESM": true      }    },    "moduleNameMapper": {      "^(\\.{1,2}/.*)\\.js$": "$1"    }  }}