Running jest with ace

Hi,
I’m trying to run jest in an ACE project. I keep getting:

SyntaxError: Cannot use import statement outside a module

it works if I do this:
“test”: “node --experimental-vm-modules ./node_modules/jest/bin/jest.js”
and this:
“type”: “module”

in package.json but then ACE won’t run (on npm start):
/app/app.js:1
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /app/app.js

Any thoughts on this please?

Hey there,

have you tried just calling jest directly in your package.json?

    "test": "jest"

You should just be able to call yarn test or node test, then.

3 Likes

Thanks, but it didn’t make it work.
What eventually worked was this:
in package.json:
in “scripts” - “test”: “node --experimental-vm-modules ./node_modules/jest/bin/jest.js”
Add this as a section:
“jest”: {
“testMatch”: [
/tests//*.?(m)js?(x)”
],
“moduleFileExtensions”: [
“js”,
“mjs”
]
}

and change the type of my files from js to mjs.

2 Likes

You can also call node -r esm to enable (E)cma (S)cript (M)odules, i.e. use ‘import’ for dependencies.