【问题标题】:Compilation Angular project fails after upgrading from 2 to 4从 2 升级到 4 后编译 Angular 项目失败
【发布时间】:2017-06-22 14:34:09
【问题描述】:

我刚刚将我的 Angular 项目从 2 升级到 4。 我是通过以下方式完成的:
1-删除 /node_modules/ 文件夹
2 次运行:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save

为了将最新版本添加到 package.json 中

3 次运行 npm 安装
++这里已经有一些奇怪的东西,在树的末端我看到:

4- 运行 ng 构建

我得到的错误信息是:

    ERROR in PATH/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts (133,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/typescript/lib/lib.es2015.iterable.d.ts (124,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/typescript/lib/lib.es2015.collection.d.ts (45,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/@types/lodash/index.d.ts (19417,15): All declarations of 'WeakMap' must have identical type parameters.

当我参加上述课程之一时,我看到一条错误消息:

说“找不到类型对象”

我的 Java 背景告诉我,我使用的编译器对“对象”的解释与库中使用的不同 事实上,我希望“对象”是一个具体的类或接口。 有什么建议吗?

这是我的 package.json

    {
  "name": "rats-gui",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/material": "^2.0.0-beta.7",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/platform-server": "^4.2.4",
    "@angular/router": "^4.2.4",
    "@types/lodash": "ts2.0",
    "angular2-datatable": "0.5.3",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "lodash": "^4.17.4",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "typescript": "^2.3.4",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^4.2.4",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "2.1.5"
  }
}

【问题讨论】:

  • 您是否尝试关闭 IDE 并运行 - npm clean cache - npm install
  • 试过:'npm cache clean' > 'npm install' > 'ng build' 仍然失败
  • 对不起,我想说 npm cache clear #清理 npm 缓存
  • 你能给我看看你的 package.json 吗?
  • 我明白了,谢谢@ZinebErrahmouni,但不幸的是问题仍然存在

标签: angular typescript


【解决方案1】:

您应该从dependencies 中删除"typescript": "^2.3.4" 条目,并将devDependencies 中的条目替换为"typescript": "^2.3.4"。最新的 Angular 版本要求 typescript 版本至少为2.2.0。

还有一些注意事项:

  • 将您的@types/lodash 移动到devDependencies 并将其更新为4.14.66
  • 从依赖项中删除@angular/compiler-cli
  • 将angular-cli 替换为"@angular/cli": "1.1.3"

最后一点可能会导致一些额外的问题,但请查看更改日志以了解重大更改。

另请查看here 了解更多升级提示

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 2020-05-12
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2019-08-02
    • 2020-08-27
    相关资源
    最近更新 更多