9

I run npm init npm i -D jest like in this tutorial

I am getting this error after running commend nmp test

This is not an error from creatures.js or creatures.test.js because without this file error happening. How can I fix this ? I tried already reinstating mode_modules. I don't know it have a matter but I'm using node 8.17.0 because I'm working with Firebase cloud functions

PS C:\Users\Pawel\Desktop\HerosIIIJS> npm test

> heros_iii_js@1.0.0 test C:\Users\Pawel\Desktop\HerosIIIJS
> jest

C:\Users\Pawel\Desktop\HerosIIIJS\node_modules\jest\node_modules\jest-cli\build\cli\index.js:227
    } catch {
            ^

SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Pawel\Desktop\HerosIIIJS\node_modules\jest\node_modules\jest-cli\bin\jest.js:16:3)
npm ERR! Test failed.  See above for more details.
const getProjectListFromCLIArgs = (argv, project) => {
  const projects = argv.projects ? argv.projects : [];

  if (project) {
    projects.push(project);
  }

  if (!projects.length && process.platform === 'win32') {
    try {
      projects.push((0, _jestUtil().tryRealpath)(process.cwd()));
    } catch { // <= error
      // do nothing, just catch error
      // process.binding('fs').realpath can throw, e.g. on mapped drives
    }
  }

  if (!projects.length) {
    projects.push(process.cwd());
  }

  return projects;
};

package.json

{
  "name": "heros_iii_js",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "jest": "^26.6.2"
  }
}

file structure:

![enter image description here

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
pawel szewczyk
  • 261
  • 2
  • 11
  • 2
    Node 8 doesn't support the optional catch binding syntax, [Jest 26](https://jestjs.io/blog/2020/05/05/jest-26#other-breaking-changes-in-jest-26) no longer supports it. – jonrsharpe Nov 03 '20 at 09:57
  • Does this answer your question? [How to fix unexpected token in ESLint?](https://stackoverflow.com/questions/62636329/how-to-fix-unexpected-token-in-eslint) – jonrsharpe Nov 03 '20 at 09:58
  • Did I need to install the newest node (I don't want to do this because Firebase cloud functions work on node 8 in spark plan) or can I chose a different jest version , how can i do this ? – pawel szewczyk Nov 03 '20 at 10:40
  • I don't use ESLint – pawel szewczyk Nov 03 '20 at 10:43
  • No, you don't use ESLint but the answer there explains what the error is and why, and you have the same options: upgrade Node; or downgrade the library to a version that supports Node 8. It also shows the command to run for the second option, you just need to replace the name and the version (version that dropped support - 1). – jonrsharpe Nov 03 '20 at 10:45
  • ok i find it i upadate my version to newwest with this https://github.com/coreybutler/nvm-windows/releases – pawel szewczyk Nov 03 '20 at 11:02
  • Well then won't you have the problem that your code might not work when you deploy it? You're testing it for a version of Node that's not what it will run on in production, that seems unwise. – jonrsharpe Nov 03 '20 at 11:03

1 Answers1

13

Upgrade node.js In old version of node they were not handled the catch block of jest file.

It will work from node -v9.11.2 to so on.

Ujjwal Jaiswal
  • 146
  • 2
  • 2