简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM