无法在npm中将Angular 2升级到4

时间:2017-03-24 11:04:55

标签: angular

我无法在npm中将Angular 2升级到4。下面是我的package.json,我在终端运行npm update --save,但是package.json没有更新到最新的Angular 4,只是保持不变。我做错了什么?

{
  "name": "todo1",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.7",
    "@angular/compiler": "^2.4.7",
    "@angular/compiler-cli": "^2.4.7",
    "@angular/core": "^2.2.3",
    "@angular/flex-layout": "2.0.0-beta.4",
    "@angular/forms": "^2.4.7",
    "@angular/http": "^2.4.7",
    "@angular/material": "^2.0.0-beta.2",
    "@angular/platform-browser": "^2.4.7",
    "@angular/platform-browser-dynamic": "^2.4.7",
    "@angular/router": "^3.4.7",
    "@types/jasmine": "^2.5.41",
    "angular2-color-picker": "^1.3.0",
    "angular2-jwt": "^0.1.28",
    "angular2-uuid": "^1.1.1",
    "core-js": "^2.4.1",
    "jasmine-spec-reporter": "^2.7.0",
    "karma": "^1.4.1",
    "lodash": "^4.17.4",
    "protractor": "^4.0.14",
    "rxjs": "^5.1.0",
    "ts-helpers": "^1.1.1",
    "ts-node": "^1.7.3",
    "tslint": "^4.1.1",
    "tslint-loader": "^3.3.0",
    "webdriver-manager": "^10.3.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.31",
    "@angular/compiler-cli": "^2.2.3",
    "@types/jasmine": "^2.5.38",
    "@types/lodash": "^4.14.52",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.22-1",
    "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.9",
    "ts-node": "^1.2.1",
    "tslint": "^4.0.2",
    "typescript": "~2.0.3",
    "webdriver-manager": "^10.2.5"
  }
}

3 个答案:

答案 0 :(得分:3)

如果您使用的是Windows,请使用以下npm命令

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

否则,您可以使用依赖项手动更新package.json文件,然后运行npm install

答案 1 :(得分:3)

我使用由角度团队创建的此工具更新了使用angular cli创建的应用程序。

https://angular-update-guide.firebaseapp.com/

答案 2 :(得分:1)

npm update没有更新major version。这是版本的第一个数字,它只更新次要版本和补丁版本。因此,如果您已经使用最新的次要版本,那么它们确实做不了多少。

您可以使用

npm install @angular/common@latest ...等

或者只是快速搜索并在package.json ^2.4.7^4.0.0替换^4.0.0。并且不要忘记将路由器更新为$table = new stdClass();,因为他们现在对齐版本:)