question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find type definitions for jest

See original GitHub issue

Describe the bug

After following the steps in Readme TS is throwing as it can’t find any of the global types.

To Reproduce Steps to reproduce the behavior:

  1. Create a new Angular CLI app (ng new app)
  2. Add Jest as described in the Jest builder Readme
  3. Update an spec to use a jest matcher, such as resolve for example.
  4. npm ng test
  5. See error

Example

jest-error.zip

Expected behavior

There should be no errors.

Builder:

  • Jest builder
  • 8.0.2

Libraries

  • angular-devkit/build-angular: ~0.800.0:

Additional context

package.json
{
  "name": "jest-error",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.0.0",
    "@angular/common": "~8.0.0",
    "@angular/compiler": "~8.0.0",
    "@angular/core": "~8.0.0",
    "@angular/forms": "~8.0.0",
    "@angular/platform-browser": "~8.0.0",
    "@angular/platform-browser-dynamic": "~8.0.0",
    "@angular/router": "~8.0.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-builders/jest": "^8.0.2",
    "@angular-devkit/build-angular": "~0.800.0",
    "@angular/cli": "~8.0.1",
    "@angular/compiler-cli": "~8.0.0",
    "@angular/language-service": "~8.0.0",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "jest": "^24.8.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
just-jebcommented, Jun 20, 2019

Ok, seems that my assumption about @types/jest being deprecated was wrong. Apparently there is still a need in this. I’m going to update the migration guide and the docs, meanwhile you can npm install -D @types/jest, get the typeRoots back and add types: ["jest"] to tsconfig.json and tsconfig.spec.json.

1reaction
just-jebcommented, Jun 17, 2019

Ok, that’s actually my bad. The README is not up to date.
The root cause of this problem is that Jest@24 comes with built in types and while I removed the “install @types/jest” step from the setup steps I forgot to update the tsconfig.json section.
Adding “types: [“jest”]” is what causes the issues. You can safely remove it from both tsconfigs (spec and root) and then you’ll be able to use jest without @types/jest. Moreover I’d strongly advise you to remove it once you removed the types entry from tsconfigs, because these are an obsolete typings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR in error TS2688: Cannot find type definition file for 'jest'
but when I run ng test I'm getting the following error: ERROR in error TS2688: Cannot find type definition file for 'jest'. Any...
Read more >
[Sovled] Jest error Cannot find name 'it' in TypeScript
To solve the "Cannot find name 'it'" jest error, make sure to install the typings for jest - npm i -D @types/jest and...
Read more >
types/jest - npm
This package contains type definitions for Jest (https://jestjs.io/). Details. Files were exported from https://github.com/DefinitelyTyped/ ...
Read more >
tsconfig.json cannot find type definition file for jest
By default ts-jest will try to find a tsconfig.json in your project. If it cannot find one, it will use the default TypeScript...
Read more >
Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found