Angular:升级到版本5错误:@angular/compiler-cli的版本需要是2.3.1或更高版本。当前版本为“5.0.0”。

7

免责声明

可能是this的重复问题,但详细问题并未展示出特定的错误信息,因此它具有歧义性和不太有用。当我在Google中输入我的错误时,我根本找不到它,因为他的问题中根本没有包含该错误。

除非其他问题被编辑以提高清晰度,否则请不要关闭这个问题,因为该错误没有其他结果。


尝试升级到v5后运行ng serve,但出现了一些错误。有人知道是怎么回事吗?根据package.json,我的@angular/compiler-cli是5.0.0...不确定为什么它说5.0.0小于2.3.1。
这是我的升级命令:
npm install @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@5.0.0

我收到了以下错误:
$ ng serve
Your global Angular CLI version (1.5.0) is greater than your local
version (1.0.0). The local Angular CLI version is used.

To disable this warning use "ng set --global warnings.versionMismatch=false".
Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "5.0.0".
Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "5.0.0".
    at Object.<anonymous> (REDACTED/node_modules/@ngtools/webpack/src/index.js:27:11)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (REDACTED/node_modules/@angular/cli/tasks/eject.js:10:19)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)

这是 package.json 文件:

{
    "name": "App",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "start-hmr": "ng serve --hmr -e=hmr",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^5.0.0",
        "@angular/common": "^5.0.0",
        "@angular/compiler": "^5.0.0",
        "@angular/core": "^5.0.0",
        "@angular/forms": "^5.0.0",
        "@angular/http": "^5.0.0",
        "@angular/platform-browser": "^5.0.0",
        "@angular/platform-browser-dynamic": "^5.0.0",
        "@angular/platform-server": "^5.0.0",
        "@angular/router": "^5.0.0",
        "@angularclass/hmr": "^1.2.2",
        "@types/jquery": "^2.0.48",
        "@types/lodash": "^4.14.73",
        "angular2-moment": "^1.7.0",
        "bootstrap": "^3.3.7",
        "core-js": "^2.5.0",
        "jquery": "^3.2.1",
        "lodash": "^4.17.4",
        "particles.js": "^2.0.0",
        "rxjs": "^5.5.2",
        "zone.js": "^0.8.16"
    },
    "devDependencies": {
        "@angular/cli": "1.0.0",
        "@angular/compiler-cli": "5.0.0",
        "@types/jasmine": "2.5.38",
        "@types/node": "^6.0.87",
        "codelyzer": "~2.0.0",
        "jasmine-core": "~2.5.2",
        "jasmine-spec-reporter": "~3.2.0",
        "karma": "~1.4.1",
        "karma-chrome-launcher": "~2.0.0",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^0.2.0",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.0",
        "ts-node": "~2.0.0",
        "tslint": "~4.5.0",
        "typescript": "~2.4.2"
    }
}

1
尝试更新本地安装的 @angular/cli(从 1.0.0 到 1.5.0),看看是否有助于消除此问题。 - R. Richards
@R.Richards,就是这样。我已经看到这个警告很长时间了,以至于现在我的眼睛完全忽略它了。几个月来从未升级本地cli,因为我除了servebuild命令之外从未使用过cli。谢谢!请随意回答,这样我就可以接受了。 - Lansana Camara
1
可能是Migrating Angular 4.x to Angular 5的重复问题。 - Aravind
2个回答

18
在这种情况下,您需要将本地安装的@angular/cli1.0.0更新到1.5.0。CLI中的许多小版本都包含了大量的更改,还伴随着这些更新所带来的依赖项变化。
要将CLI的本地版本更新到最新版本,请在打开到项目根目录的命令提示符/终端中使用以下命令。
npm install --save-dev @angular/cli@latest

或者,您可以在package.json中更新版本,然后运行npm install

您可以隐藏CLI显示的警告,当全局和本地CLI版本不同步时,但那可能会掩盖任何问题的解决方案。要隐藏警告,请运行此命令:

ng set --global warnings.versionMismatch=false

最好将本地版本和全局版本保持同步,以避免出现问题。


我遇到了angular.json错误,以下命令解决了这个问题。ng update @angular/cli --migrate-only --from=1.7.4它创建了新的angular.json并删除了.angular-cli.json。 - crazyCoder

0
在最新的Angular 7或以上版本中,请使用以下命令。
npm install --save-dev @angular/cli@latest
ng config -g cli.warnings.versionMismatch false

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接