Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading