繁体   English   中英

尝试将 jest 与 create-react-app 和 typescript 一起使用。 获取错误:开玩笑:无法解析 TypeScript 配置文件...找不到模块“ts-node”

[英]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.

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