Cannot find type definitions for jest
See original GitHub issueDescribe 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:
- Create a new Angular CLI app (ng new app)
- Add Jest as described in the Jest builder Readme
- Update an spec to use a jest matcher, such as
resolve
for example. - npm
ng test
- See error
Example
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:
- Created 4 years ago
- Comments:23 (20 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 cannpm install -D @types/jest
, get thetypeRoots
back and addtypes: ["jest"]
totsconfig.json
andtsconfig.spec.json
.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 thetypes
entry from tsconfigs, because these are an obsolete typings.