user2923322
user2923322

Reputation: 1142

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 https://jestjs.io/docs/ecmascript-modules

However, I still have the error:

export {
^^^^^^

SyntaxError: Unexpected token 'export'

The source of the error comes from a dependency: node_modules\object-array-utils

The version of Node is v17.4.0

Upvotes: 3

Views: 10171

Answers (1)

Szaman
Szaman

Reputation: 2388

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.

Upvotes: 3

Related Questions