Why am i getting Unknown option "extensionsToTreatAsEsm" using jest

Publish date: 2024-07-12

From the documentation here, it looks like I should be able to add the following to my jest config extensionsToTreatAsEsm: [".js", ".mjs"],. But when I run I get

Unknown option "extensionsToTreatAsEsm" with value [".js", ".mjs"] was found. This is probably a typing mistake. Fixing it will remove this message. 

I am on latest so what am I missing?

2 Answers

I was getting the same error seems like it's still experimental and my build was failing on GitHub. For the time being I went without the native ESM modules configuration in jest.config.js

extensionsToTreatAsEsm [array < string >]

Jest will run .mjs and .js files with nearest package.json's type field set to module as ECMAScript Modules. If you have any other files that should run with native ESM, you need to specify their file extension here. Note: Jest's ESM support is still experimental, 

I've managed to resolve this by providing

 "jest": { "extensionsToTreatAsEsm": [".ts"] } 

option in the package.json instead of jest.config.ts.

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXFrZmmAeoWOsJ%2ByZZGieqp5xp6rraGenHq2usqnprCmXaS9tbXOp2SesKSau7S1zqeqraekp7KiwMCsnKylXarAqrrGZqGeq6Q%3D