【问题标题】:Errors after updating tsconfig.json and package.json更新 tsconfig.json 和 package.json 后的错误
【发布时间】:2017-05-19 03:07:19
【问题描述】:

在某些情况下,我刚刚开始浏览此处找到的 Ahead-of-time 编译食谱,但我不相信我的错误与它直接相关:https://angular.io/guide/aot-compiler

我正在使用 Visual Studio 2015 并将我的 Angular 2 项目更新到新发布的 2.4 并且一切都构建得很好。然后,我更改了我的 tsconfig.json 文件,将 "lib": [ "es2015", "dom" ] 添加到我的 compilerOptions。该文件现在看起来像这样:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "removeComments": false,
    "noImplicitAny": true,
    "outDir": "dist",
    "suppressImplicitAnyIndexErrors": true
  },
  "compileOnSave": true
}

这个改动后,我重新构建并得到以下构建错误:

构建:重复标识符“PropertyKey”。

我做了一些研究并决定从我的 package.json 文件中删除 "@types/core-js": "^0.9.34",这似乎已经解决了该错误,但我现在有几个出现以下新错误的实例:

构建:找不到名称“Set”

构建:找不到名称“承诺”

构建:找不到名称“地图”

这是我的完整 package.json 文件:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "docker-build": "docker build -t ng2-quickstart .",
    "docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
    "pree2e": "npm run webdriver:update",
    "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "postinstall": "typings install",
    "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
    "test-once": "tsc && karma start karma.conf.js --single-run",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "webdriver:update": "webdriver-manager update"
  },
  "license": "MIT",
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/compiler-cli": "^2.4.1",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/platform-server": "^2.4.1",
    "@angular/router": "~3.4.0",
    "@angular/upgrade": "~2.4.0",
    "angular-in-memory-web-api": "~0.1.16",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.1",
    "systemjs": "0.19.39",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "@types/node": "^6.0.45",
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3"
  },
  "repository": {}
}

为了不断更新新版本,我几乎一直在此处复制示例 package.json 文件的依赖项部分:https://angular.io/guide/quickstart

该链接适用于 JavaScript 版本,因为这是我能找到的唯一一个,但我实际上使用的是 TypeScript 2.1.4。正因为如此,我可能有这个文件的某些部分已经过时了。我只是不确定如何具体确定哪些部分。

【问题讨论】:

标签: angular typescript angular2-aot


【解决方案1】:

我不熟悉 Visual Studio 设置(intellij 用户)。但也许 尝试使用。 “lib”:[“es6”,“dom”],或者可能删除“lib”:[ "es20125", "dom" ],完全尝试使用 core-js @types。看着 我在这里对如何使用 core-js 的回答。

相关答案:

Angular 2 can't find Promise,Map,Set and Iterator

Cannot find name 'Promise' 这个错误让我相信你缺少 ES6 的类型定义。

Promise、Map 和 Set 是 es6 规范。

您应该使用 ES6 pollyfill 库。

【讨论】:

    猜你喜欢
    • 2021-11-08
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多