standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

How to enable es6 import modules in Jest in a ESM used back-end? #875

Open pouyajabbarisani opened 4 years ago

pouyajabbarisani commented 4 years ago

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?

ivanbacher commented 4 years ago

Any luck?

Romakita commented 4 years ago

@pouyajabbarisani The better solution is to use Babel to transpile ES6 import ;)

See you Romain

jsg2021 commented 4 years ago

Take a look at the jest directories under https://github.com/standard-things/esm/tree/master/test/fixture/scenario