Jest: SyntaxError: Unexpected token at _load_jsdom

Created on 10 Jan 2018  ยท  2Comments  ยท  Source: facebook/jest

Tried all of the above and using a brand new empty project with nothing but the sum getting started code.

Do you want to request a _feature_ or report a _bug_?

Bug

What is the current behavior?

When running npm test, I get the following:

FAIL ./sum.test.js
โ— Test suite failed to run

SyntaxError: Unexpected token {

  at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

  1. Express Generate a fresh node.js app with all defaults.
  2. npm install (to update all dependencies)
  3. npm install jest --save (jest is 1.11.0)
  4. Add sum.js and code from sample
  5. Add sum.test.js and code from sample
  6. Update package.json with
    "scripts": {
    "test": "jest"
    }
  7. npm test

this is where I get the error:

SyntaxError: Unexpected token {

  at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)

Sorry I do not have time for repl, but this could make or break my fortune 100 (Sorry, cannot disclose publicly) company's adoption of using this.

Most helpful comment

Answered my own question: the jest dependency jest-environment-jsdom is by default incompatible with node versions < 10. To fix, add the following to your jest config in package.json:

  "jest": {
    "testEnvironment": "node",
    ...other config
  },

All 2 comments

@jpmock running into the same issue. did you solve?

Answered my own question: the jest dependency jest-environment-jsdom is by default incompatible with node versions < 10. To fix, add the following to your jest config in package.json:

  "jest": {
    "testEnvironment": "node",
    ...other config
  },
Was this page helpful?
0 / 5 - 0 ratings