Why am i getting Unknown option "extensionsToTreatAsEsm" using jest

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like