2

I'm using a NodeJs backend with ESM package enabled mode to use es6+ import modules system when I'm trying to access a file in my test, even if I use require in my test file because target file uses import/export, it throws this error:

SyntaxError: Cannot use import statement outside a module

I know, I can use babel to solve Jest problem, but due to my main project files (which are using ESM), is there any solution to config Jest with ESM?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Pouya Jabbarisani
  • 1,084
  • 3
  • 16
  • 29
  • 1
    Does this answer your question? [Node v13 / Jest / ES6 — native support for modules without babel or esm](https://stackoverflow.com/questions/60372790/node-v13-jest-es6-native-support-for-modules-without-babel-or-esm) – Nino Filiu May 07 '20 at 08:32

1 Answers1

2

I have a good news to you. Jest supports esm natively from version 25.4.0. It is not documented yet, but I wrote here, how to achieve that.

I hope, it will help to you.

Radovan Kuka
  • 1,962
  • 1
  • 17
  • 19