ERROR in error TS2688: Cannot find type definition file for 'jest'
Asked Answered
U

2

20

I have an angular 6 application and I'm using karma + jasmine to run my tests. but when I run ng test I'm getting the following error:

ERROR in error TS2688: Cannot find type definition file for 'jest'.

Any one knows how to solve this problem?

Ultranationalism answered 10/12, 2018 at 16:8 Comment(0)
U
9

I didn't realized that in my tsconfig.spec.json I was using jest instead of jasmin in types node. Also, I had a missing configuration.

So, I have changed from this:

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

To this:

{
  "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"
  ]
}

And this changes solves my problem.

Ultranationalism answered 11/12, 2018 at 12:11 Comment(3)
Adding "node" to my "types" array in tsconfig.json worked for me - not sure why - but it worked! thanks.Clarendon
@Clarendon how did you even came up with that ? why node ?Cohby
I just had to add the specs and d types to my include path.Twoup
I
24

As of Aug 2023, if you are using the latest version of @testing-library/jest-dom, all you need to do is remove @types/testing-library_jest-dom.

Indwell answered 20/8, 2023 at 8:59 Comment(4)
Live saver comment.Cancan
Not helping for me. Still the same error.Polyneuritis
Please run npm i or pnpm i or yarn install to re-install the packages and remove the packages that are removed from package.json. Or try deleting node_modules directory and package-lock file and install all packages againIndwell
Is there a certain version of jest-dom that made the import @types/testing-library_jest-dom obsolete?Chaetopod
U
9

I didn't realized that in my tsconfig.spec.json I was using jest instead of jasmin in types node. Also, I had a missing configuration.

So, I have changed from this:

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

To this:

{
  "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"
  ]
}

And this changes solves my problem.

Ultranationalism answered 11/12, 2018 at 12:11 Comment(3)
Adding "node" to my "types" array in tsconfig.json worked for me - not sure why - but it worked! thanks.Clarendon
@Clarendon how did you even came up with that ? why node ?Cohby
I just had to add the specs and d types to my include path.Twoup

© 2022 - 2024 — McMap. All rights reserved.