【问题标题】: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'尝试将 jest 与 create-react-app 和 typescript 一起使用。获取错误:Jest:无法解析 TypeScript 配置文件...找不到模块“ts-node”
【发布时间】:2022-01-02 16:33:52
【问题描述】:

我已经使用 typescript 设置了一个 create-react-app,遵循此页面上的文档:https://create-react-app.dev/docs/adding-typescript/,然后遵循此页面:https://jestjs.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。包.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"
  },

应用运行正常,但我无法进行测试?

【问题讨论】:

    标签: javascript reactjs typescript jestjs create-react-app


    【解决方案1】:

    它没有安装 test-jest 也没有 jest 配置

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 2018-06-27
      • 2019-09-02
      • 2019-06-08
      • 1970-01-01
      • 2021-10-03
      相关资源
      最近更新 更多