Environment variables validation not working with Jest (env.mjs)

Hi, did anyone else have problems with env.mjs in tests (I use env.SOME_VAR in my components)? I get this error:
.../env.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { z } from "zod";

SyntaxError: Cannot use import statement outside a module
.../env.mjs:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { z } from "zod";

SyntaxError: Cannot use import statement outside a module
It's fixable by using babel.config.js, but I don't want to use babel (I have NX monorepo)... 🫣
3 Replies
rbatsenko
rbatsenkoOP•2y ago
Solved it by migrating my tests to Vitest lol 😀 🤘
twistable
twistable•2y ago
It's not solved though. I have the same problem
rbatsenko
rbatsenkoOP•2y ago
Yeah all this esm stuff is super annoying in JS...
Want results from more Discord servers?
Add your server