1

所以,我已经尝试学习Angular 2了几天(Github Repo)。对于单元测试,我一直在尝试配置JasmineKarma. 我一直在关注这些项目作为基础

1)使用 Karma 和 Jasmine 测试 Angular 2

2)种子Angular2应用

但是,由于某些原因,我没有正确配置。可能是由于缺乏前端开发经验。

首先,我收到消息错误:

node_modules/angular2/platform/browser.d.ts(77,90): error TS2304: Cannot find name 'Promise'.

我在这里发现了类似的问题, 并按照此处提到的解决方案进行操作

但是现在我收到以下错误:

node_modules/rxjs/Observable.d.ts(1,1): error TS2654: Exported external package typings file cannot contain tripleslash references. Please contact the package author to update the package definition.
node_modules/rxjs/Observable.d.ts(12,6): error TS2304: Cannot find name 'Symbol'.
node_modules/rxjs/Observable.d.ts(15,42): error TS2304: Cannot find name 'Iterable'.

对于这个错误,我没有找到任何令人信服的解决方案。那么,有人可以帮我解决这个问题吗?

提前致谢。

配置详情:

1) 包.json

{
  "name": "learning",
  "version": "1.0.0",
  "description": "Learning Angular 2",
  "main": "index.js",
  "scripts": {
    "build": "rm -rf dist && tsc -p src/",
    "start": "tsc && concurrently \"npm run tsc:w\" \"http-server -c-1 -o -p 8875 .\" ",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "pretest": "npm run build",
    "test": "karma start karma.conf.js",
    "posttest": "node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html",
    "coverage": "http-server -c-1 -o -p 9875 ./coverage",
    "typings": "typings",
    "postinstall": "typings install"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "angular2": "^2.0.0-beta.14",
    "es6-promise": "^3.1.2",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "^5.0.0-beta.5",
    "zone.js": "^0.6.10"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "http-server": "^0.9.0",
    "jasmine-core": "^2.4.1",
    "karma": "^0.13.22",
    "karma-chrome-launcher": "^0.2.3",
    "karma-coverage": "^0.5.5",
    "karma-jasmine": "^0.3.8",
    "remap-istanbul": "^0.5.1",
    "systemjs": "^0.19.25",
    "typescript": "^1.8.9",
    "typings":"^0.7.12"
  }
}

2) tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "removeComments": true,
    "declaration": true,
    "outDir": "../dist"
  },
  "exclude": [
    "node_modules"
  ]
}
4

2 回答 2

2

这是 rxjs bet 5 中的一个错误。等待 beta 6 或降级到 4 使用

 npm install rxjs@5.0.0-beta.4 --save.
于 2016-04-12T13:04:18.540 回答
0

您需要在您的应用程序入口点中引用定义文件:

/// <reference path="node_modules/angular2/typings/browser.d.ts" />

https://github.com/angular/angular/issues/7280

于 2016-04-12T11:49:34.747 回答