Angular编译器找不到jasmine.CustomMatchers,即使它位于@ types / jasmine中

问题描述 投票:2回答:2

我刚从Angular guide下载了示例测试项目:https://angular.io/generated/zips/testing/testing.zip

当我做ng serve我得到错误:

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

我对Angular很新。有人能帮我理解什么是错的吗?

我已经完成了npm install,当我转到node_modules / @ types / jasmine时,我可以看到CustomMatchers在index.d.ts中定义

Angular 7

打字稿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",
angular typescript karma-jasmine
2个回答
1
投票

事实证明,错误是由不兼容的Typescript和@ types / jasmine包版本引起的。以下版本应该有效:

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"

要安装正确的版本,请执行以下操作:

删除package-lock.json和node_modules /然后执行npm cache clean --forcenpm install


0
投票

我有nodenpm版本如下:

node --version
v10.15.3

npm --version
6.9.0

我收到如下错误:

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'.

src/app/model/testing/index.ts文件中注释下面的一行修复了该问题。

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

看起来它也有与jasmineCustomMatcher有关的错误。但事实并非如此。

有趣的是,当我停止服务器并使用ng serve重新运行时,我再次得到jasmin相关错误。但是当我通过在注释行中添加一个空格来编辑上面提到的文件(index.ts)时,它就被成功编译了!

这是我的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"
}
© www.soinside.com 2019 - 2024. All rights reserved.