Ts-jest: Problem with version (one of: ts-jest, typescript, @types/jest)

Created on 8 Aug 2018  Â·  6Comments  Â·  Source: kulshekhar/ts-jest

I'll update package.json and found issue

_Jest encountered an unexpected token_ (...) _SyntaxError: Unexpected token ' in JSON at position 27_

before:
"@types/jest": "^22.2.3", "jest": "^22.0.0", "ts-jest": "^22.0.0", "typescript": "^2.8.0"

changes:
@types/jest ^22.2.3 → ^23.3.1
jest ^22.0.0 → ^23.4.2
ts-jest ^22.0.0 → ^23.1.3
typescript ^2.8.0 → ^3.0.1

after:
"@types/jest": "^23.3.1", "jest": "^23.4.2", "ts-jest": "^23.1.3", "typescript": "^3.0.1"

Details:
SyntaxError: Unexpected token ' in JSON at position 27 at JSON.parse (<anonymous>) at read (node_modules/ts-jest/src/utils/get-babel-rc.ts:13:21) at readers.find (node_modules/closest-file-data/dist/index.js:30:32) at Array.find (native) at Object.closestFileData [as default] (node_modules/closest-file-data/dist/index.js:27:17) at Object.getBabelRC [as default] (node_modules/ts-jest/src/utils/get-babel-rc.ts:20:30) at Object.getCacheKey (node_modules/ts-jest/src/utils/get-cache-key.ts:23:15)

$ node --version v8.9.0
$ npm --version 6.3.0

All 6 comments

Hi @rpCal you must have a syntax error in your package.json. Do you mind posting it here?

@huafu Thank you for quick response. Sure... it's a package.json

{
  "name": "udemy-react-the-complete-guide",
  "version": "1.0.0",
  "description": "",
  "main": "01_intro_js.js",
  "scripts": {
    "test": "jest --watchAll"
  },
  "engines": {
    "node": ">=8"
  },
  "repository": {},
  "author": "",
  "license": "ISC",
  "bugs": { },
  "dependencies": {},
  "devDependencies": {
    "babel-jest": "^23.4.2",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "@types/jest": "^22.2.3",
    "jest": "^22.0.0",
    "ts-jest": "^22.0.0",
    "typescript": "^2.8.0"
  }
}

sorry, it's actually your babelrc that is having syntax issue, I read too quickly. Can you provide your babelrc here plz? (put it between tripple backtilt ```)

Yes... Now I don't use that babel in jest.transform

jest.config.js

module.exports = {
    transform: {
        "^.+\\.tsx?$": "ts-jest",
    },
    testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    testPathIgnorePatterns: ["/lib/", "/node_modules/"],
    moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
    collectCoverage: false,
    verbose: true,
    testURL: "http://localhost/",
};

.babelrc

{
    "presets": [
        'env', 'react'
    ],
    "plugins": ["transform-object-rest-spread"]
}

yeah you see the issue is that in .babelrc file you used single quotes ' instead of doubles ". it should be:

{
    "presets": [
        "env", "react"
    ],
    "plugins": ["transform-object-rest-spread"]
}

ts-jest uses babel under the hood for hosting and some other tinghs

It's shock for me, Thank you sooo much! It's working now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GeeWee picture GeeWee  Â·  4Comments

mikeyakymenko picture mikeyakymenko  Â·  3Comments

qm3ster picture qm3ster  Â·  3Comments

Vinnl picture Vinnl  Â·  3Comments

TKJohn picture TKJohn  Â·  4Comments