[英]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'
我已經使用 typescript 設置了一個 create-react-app,遵循此頁面上的文檔: https://create-react-app.dev/docs/adding-typescript/然后關注此頁面: Z5E056C500A1C4BADE5Z11 .io/docs/getting-started
當我嘗試運行腳本時: jest sum --notify
我收到以下錯誤:
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'
但是我的依賴項中安裝了ts-node
。 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"
},
該應用程序運行正常,但我無法進行測試?
它沒有安裝 test-jest 也沒有 jest 配置
1, yarn add --dev ts-jest @types/jest
2, yarn ts-jest config:init
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.