【问题标题】:ERROR in error TS2688: Cannot find type definition file for 'jest'错误 TS2688 中的错误:找不到“jest”的类型定义文件
【发布时间】:2019-05-11 13:46:39
【问题描述】:

我有一个 Angular 6 应用程序,我正在使用 karma + jasmine 来运行我的测试。但是当我运行ng test 时出现以下错误:

错误 TS2688 中的错误:找不到“jest”的类型定义文件。

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: angular jasmine angular6 angular-cli karma-runner


    【解决方案1】:

    我没有意识到在我的tsconfig.spec.json 中我使用的是jest 而不是jasmin 节点中的jasmin。另外,我缺少配置。

    所以,我已经改变了:

    {
      "extends": "./tsconfig.es5.json",
      "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "../out-tsc/spec",
        "module": "commonjs",
        "target": "es6",
        "baseUrl": "",
        "types": [
          "jest",
          "node"
        ]
      },
      "files": [
        "**/*.spec.ts"
      ]
    }
    

    到这里:

    {
      "extends": "./tsconfig.es5.json",
      "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "outDir": "../out-tsc/spec",
        "module": "commonjs",
        "types": [
          "jasmine",
          "node"
        ]
      },
      "files": [
        "test.ts",
        "polyfills.ts"
      ],
      "include": [
        "**/*.spec.ts",
        "**/*.d.ts"
      ]
    }
    

    而这个改变解决了我的问题。

    【讨论】:

    • 在 tsconfig.json 中将“节点”添加到我的“类型”数组中对我有用 - 不知道为什么 - 但它有效!谢谢。
    • @simbro 你是怎么想到的?为什么是节点?
    猜你喜欢
    • 2019-07-10
    • 2021-05-14
    • 1970-01-01
    • 2022-10-20
    • 2018-07-23
    • 2018-02-24
    • 2018-03-09
    • 2017-09-08
    • 2019-10-10
    相关资源
    最近更新 更多