简体   繁体   English

如何升级角度编译器以处理打字稿3+

[英]How to upgrade the angular compiler to process typescript 3+

To fix a compiler probelem, I had to upgrade to typecript 3+, somehow I can't get the angular compiler to process it. 为了解决编译器问题,我不得不升级到typecript 3+,以某种方式我无法让angular编译器来处理它。

ERROR in The Angular Compiler requires TypeScript >=2.7.2 and <2.10.0 but 3.1.6 was found instead.

I deleted node_modules , deleted package-lock.json , changed package.json and ran npm install . 我删除了node_modules ,删除了package-lock.json ,更改了package.json并运行了npm install I took the version from a project I generated using ng new 我从使用ng new生成的项目中获取了版本

As far as I read TS 3+ shold work with angular 7. So I tried it. 据我所知,TS 3+支架的角度为7。 Currently my package.json looks like this. 目前,我的package.json看起来像这样。

I could downgrade TS to fix this problem, but then I have the old issue, so this is NO option for me. 我可以降级TS来解决此问题,但是我有个老问题,所以这对我来说是没有选择的。

{
  "name": "workouttracker",
  "version": "0.1.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^7.3.7",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/material": "^7.3.7",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@ckeditor/ckeditor5-angular": "^1.1.0",
    "@ckeditor/ckeditor5-build-classic": "^12.1.0",
    "@ng-bootstrap/ng-bootstrap": "^4.2.1",
    "@types/webpack-env": "^1.13.9",
    "blueimp-canvas-to-blob": "^3.14.0",
    "bootstrap": "^4.3.1",
    "chart.js": "^2.8.0",
    "core-js": "^2.5.4",
    "crypto-js": "^3.1.9-1",
    "emailjs-com": "^2.3.2",
    "firebase": "^6.1.0",
    "font-awesome": "^4.7.0",
    "google-maps": "^3.3.0",
    "googlemaps": "^1.12.0",
    "jquery": "^3.4.1",
    "material": "^0.3.13",
    "ng-bootstrap": "^1.6.3",
    "ng2-ckeditor": "^1.2.3",
    "ng2-img-max": "^2.1.18",
    "popper.js": "^1.15.0",
    "require": "^2.4.20",
    "rxjs": "~6.2.0",
    "ts-loader": "^5.4.5",
    "zone.js": "^0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.8.9",
    "@angular/cli": "^7.3.9",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/hammerjs": "^2.0.36",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^8.10.49",
    "codelyzer": "~4.3.0",
    "hammerjs": "^2.0.8",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.2",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }
}

Installed Angular CLI 已安装的Angular CLI

Angular CLI: 7.3.9
Node: 8.12.0
OS: win32 x64
Angular: 7.0.4
... common, compiler, core, forms, http, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.9
@angular-devkit/build-angular     0.8.9
@angular-devkit/build-optimizer   0.8.9
@angular-devkit/build-webpack     0.8.9
@angular-devkit/core              0.8.9
@angular-devkit/schematics        7.3.9
@angular/animations               7.2.15
@angular/cdk                      7.3.7
@angular/cli                      7.3.9
@angular/compiler-cli             6.1.10
@angular/fire                     5.2.1
@angular/language-service         6.1.10
@angular/material                 7.3.7
@ngtools/webpack                  6.2.9
@schematics/angular               7.3.9
@schematics/update                0.13.9
rxjs                              6.2.2
typescript                        3.1.6
webpack                           4.16.4

I want to run ng build with no errors. 我想没有错误地运行ng build。

PROBLEM: 问题:

You are using: 您正在使用:

"@angular/compiler-cli": "^6.1.0",

And this is a 'slice' of the package json of @angular/compiler-cli version 6.xx: 这是@ angular / compiler-cli版本6.xx的json包的“切片”:

  "peerDependencies": {
    "typescript": ">=2.7.2 <2.8",
    "@angular/compiler": "0.0.0-PLACEHOLDER"
  },

So yes, this version of compiler cli must use Typescript 2.7 所以是的,此版本的cli cli必须使用Typescript 2.7

SOLUTION: 解:

You need to upgrade @angular/compiler-cli to a version 7.xx . 您需要将@ angular / compiler-cli升级到版本7.xx。 And this makes totally sense in fact, since in order to use Angular 7, all Angular packages must be at 7.xx . 这实际上是完全有意义的,因为要使用Angular 7, 所有Angular软件包都必须位于7.xx处

This one: "@angular/language-service": "^6.1.0", should have to be upgraded to 7.xx too. 这个: "@angular/language-service": "^6.1.0",应该也升级到7.xx。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM