Angular compiler can't find jasmine.CustomMatchers even though it's in the @types/jasmine

Viewed 1625

I just downloaded example testing project from Angular guide: https://angular.io/generated/zips/testing/testing.zip

When I do ng serve I get errors:

src/testing/jasmine-matchers.d.ts(3,67): error TS2694: Namespace 'jasmine' has no exported member 'CustomMatcher'.

I am fairly new to Angular. Could someone help me understand what's wrong?

I have done npm install and when I go to node_modules/@types/jasmine I can see that CustomMatchers is defined in index.d.ts

Angular 7

Typescript 3.0

"@types/jasmine": "^2.8.14",
"@types/jasminewd2": "^2.0.4",
"@types/node": "~8.9.4",
"jasmine-core": "~2.99.1",
"jasmine-marbles": "^0.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
2 Answers

It turns out that the errors are caused by incompatible versions of Typescript and @types/jasmine packages. The following versions should work:

Angular CLI: 6.2.9
Node: 10.11.0
OS: darwin x64
Angular: 6.1.10
typescript                        2.7.2
"@types/jasmine": "2.8.9"

In order to install correct versions do the following:

remove the package-lock.json and node_modules/ then do npm cache clean --force and npm install

I have node and npm version as below:

node --version
v10.15.3

npm --version
6.9.0

I got error as below:

ERROR in src/app/model/testing/index.ts(1,15): error TS2307: Cannot find module './fake-hero.service'.
src/testing/jasmine-matchers.d.ts(3,67): error TS2694: Namespace 'jasmine' has no exported member 'CustomMatcher'.
src/testing/jasmine-matchers.ts(7,3): error TS2708: Cannot use namespace 'jasmine' as a value.
src/testing/jasmine-matchers.ts(12,32): error TS2694: Namespace 'jasmine' has no exported member 'CustomMatcher'.
src/testing/jasmine-matchers.ts(14,97): error TS2694: Namespace 'jasmine' has no exported member 'CustomMatcherResult'.

Commenting a line as below from the file src/app/model/testing/index.ts fixed the issue.

//export * from './fake-hero.service';

It seems like it also has error related to jasmine and CustomMatcher. But it is not.

Interestingly when I stopped the server and re-run using ng serve, I got jasmin related error again. But when I edited the above mentioned file(index.ts) by just putting a space in the comment line, it is compiled successfully!

Here is my devDependencies:

"devDependencies": {
  "@angular-devkit/build-angular": "^0.11.0",
  "@angular/cli": "^7.1.0",
  "@angular/compiler-cli": "^7.1.0",
  "@angular/platform-server": "^7.1.0",
  "@types/jasmine": "~2.8.8",
  "@types/jasminewd2": "^2.0.4",
  "@types/node": "~8.9.4",
  "jasmine-core": "~2.99.1",
  "jasmine-marbles": "^0.4.0",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~3.0.0",
  "karma-chrome-launcher": "~2.2.0",
  "karma-coverage-istanbul-reporter": "~2.0.1",
  "karma-jasmine": "~1.1.2",
  "karma-jasmine-html-reporter": "^0.2.2",
  "lodash": "^4.16.2",
  "protractor": "~5.4.0",
  "ts-node": "~7.0.0",
  "tslint": "~5.11.0",
  "typescript": "~3.1.1"
}
Related