Jest Build Failure "Unexpected token {"


#1

Hi guys!

I’ve been trying to set up my build with npm to run jest for testing. The testing works on my local machine, however, when circle is building it it returns with this error:

SyntaxError: Unexpected token {
  
  at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:18:19)

I’ve been trying to find more about the problem and came across this other discussion on this thread. They recommended updating the node to a more up to date version, however, I come across the same result. I’ve already changed the version to 8.9.4 and to 8.10 (the same as my local machine). I’ve read about other cases, and the suggestions I’ve read hasn’t been all too helpful.

Currently I’m trying to find a way to access the SSH, but i want to see if there something I need to change on my config file.

Here is my config file for reference:

version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:8.9.4
  
  # Specify service dependencies here if necessary
  # CircleCI maintains a library of pre-built images
  # 
  # documented at https://circleci.com/docs/2.0/circleci-images/
  # - image: circleci/mongo:3.4.4

working_directory: ~/repo

steps:
  - checkout

  # Download and cache dependencies
  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "package.json" }}
      # fallback to using the latest cache if no exact match is found
      - v1-dependencies-

  - run: npm install

  - save_cache:
      paths:
        - node_modules
      key: v1-dependencies-{{ checksum "package.json" }}
    
  # run tests!
  - run: npm test

Any guidance would be much appreciated!


#2

I don’t use Node. However, I recall someone recently here who mentioned they used the circleci/node and they tried to install/upgrade something (either Node or NPM) and it didn’t appear to work. I had the theory that the new thing was in the wrong PATH order, and so was not actually taking effect.

If you are stuck, try making sure the new thing is being used (use npm -v prior to your install). Or you could try using a blank image and install Node from scratch, so you only have one version available.

I would reiterate my favourite bit of advice here, which is that high-level errors from a programming language are rarely the fault of a CI system - CI is just a VPS with a bunch of tools. More often than not, the solution can be found by treating the error as if you had it in your development machine, and working from that assumption in the debugging/research you do.


#3

Thanks for the reply! That does make sense. I’m going to explore the install further and see where it’s causing this error, God willing.


#4

So I’ve been looking at the logs, and it says that my node version is still on 4.2.6. I’ve been adjusting the version on my yml to set to one of the pre-built version, and for some reason it won’t change the node version. I’ve been looking at the different pre-built images, and trying to rebuild without the cache, but I come across the same error. I’ve read that it might be building from the wrong branch, but each branch has the same file.

To test it out, I’ve commented out the testing, and it is still running it. Would you happen to have any ideas on why that would be acting like that?


#5

Yes, it’s probably a PATH problem, as I say. See this.


#6