Jest: SyntaxError: Unexpected token 'export'

I added the following in the package.json file:

"scripts": {
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
"jest": {
  "testEnvironment": "jest-environment-node",
  "transform": {}
"type": "module",

This should be sufficient

However, I still have the error:

export {

SyntaxError: Unexpected token ‘export’

The source of the error comes from a dependency:

The version of Node is v17.4.0

>Solution :

It appears to me that there is an issue in the package you’re using. It’s trying to use ES modules syntax (import / export) but to do that, it needs to declare it in its package.json file:

  "type": "module",

See this guide for example to get more info about ES modules.

PS. for similar errors / people finding this in the future: locate which package the error is coming from and see if it continues to occur if you remove that package. If not, then the issue is with the package. If you’re seeing the same error but for different files, you might have an issue with your jest config.

Leave a Reply