JimmyTheCode
JimmyTheCode

Reputation: 5694

Trying to use jest with create-react-app and typescript. Get error: Jest: Failed to parse the TypeScript config file... Cannot find module 'ts-node'

I've set up a create-react-app with typescript, following the documentation on this page: https://create-react-app.dev/docs/adding-typescript/ and then following this page: https://jestjs.io/docs/getting-started

When I try to run the script: jest sum --notify I get the following error:

Error: Jest: Failed to parse the TypeScript config file /home/.../jest-playground/jest.config.ts
  Error: Jest: 'ts-node' is required for the TypeScript configuration files. Make sure it is installed
Error: Cannot find module 'ts-node'

But I have ts-node installed in my dependencies. package.json:

  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "ts-jest": "^27.0.7",
    "ts-node": "^10.4.0",
    "typescript": "^4.1.2",
    "web-vitals": "^1.0.1"
  },

The app runs OK, but I can't get the testing to work?

Upvotes: 0

Views: 1366

Answers (1)

Maugham
Maugham

Reputation: 61

it not have install test-jest and have't jest config

1, yarn add --dev ts-jest @types/jest
2, yarn ts-jest config:init

Upvotes: 1

Related Questions