Jest and Node.js build failure: "SyntaxError: Unexpected token {"

nodejs
circle.yml

#1

I recently started using CircleCI. I first built a simple GitHub “Hello World”-type repository, wrote some JS code there, wrote unit tests with Jest inside a subfolder, and successfully hooked it up to CircleCI.

What I really want is to have a set of subfolders within a repository and run tests from there. I ran into the “no tests found” issue and set up a circle.yml file inside the repo root, pointing it to sub-folder as the build-dir.

When I now push to GitHub, I get the followingCircleCI error:
“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)”.

It sounds as if there is a problem with installing Jest, possibly due to versioning, but I am using the exact same version of Node and Jest that I used in the simpler “Hello World” repository where I first tested CircleCI. All Jest tests run when tested locally through “npm test”.

GitHub repo: https://github.com/Carla-de-Beer/Continuous-Integration
From there, the tests are inside the “tests” folder within “MatrixLibrary”.

I have been struggling myself silly on this one. Any advice would be appreciated.


#2

I’ve no idea on Node/JS problems, I don’t use it. However, I’d treat this as a JS problem rather than a CircleCI issue. I’d start off with kicking off a failing build with SSH, so you can spend time at the console of a failed build machine. Just remember that SSH time eats your build minutes!

From there, treat this as a Node problem. There are plenty of possible solutions on Stack Overflow, perhaps one of them will fit your case?


#3

experiencing the same issue. seems to be CircleCI bug?


Jest Build Failure "Unexpected token {"
#4

Without any further detail, it is unlikely anyone can say :stuck_out_tongue_winking_eye:

Remember that CircleCI are basically giving you access to virtual servers. What you do with it is up to you, and in Docker 2.0 you can pretty much fix anything yourself.

Certainly, they may be a problem with a pre-built image supplied by Circle, but we’d need to know which one you are having issues with. And, of course, you can just start with an pristine OS image (e.g. plain Docker) and build what you want on it.


#5

I managed to find a solution to this issue. I used to get the exact same error previously when I tested locally because my version of node was badly out of date. When I upgraded to the latest version of Node, the problem disappeared and the tests passed. It made me think that I needed to tell CircleCI to use a specific version of node in order to run the tests.

Solution: explicitly specify the version of node that you need to test on as part of the circle.yml file. In my case, I used the following (in addition to specifying the working_directory, even though thsi is specified in the config.yml file):

machine:
  node:
    version: 8.9.4

#6

That looks like it was meant to be YAML. Would you edit your post to add block/code formatting, so the essential indentation is visible? (I will delete this message once you have done so).


#7

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.