在angular2-cli项目中升级angular 2依赖项

时间:2016-07-08 01:41:12

标签: javascript angular npm angular2-cli

在使用angular2并在他们的网站上跟随angular2指南后,我试图转移到angular2-cli,但angular2-cli项目没有最新的依赖项,因此编译器在代码中给出了一些关于某些命令的错误。

我想升级所有依赖项,例如核心,路由器等。 最新的路由器需要最新的核心,但是当我尝试这样做时:npm install core -g,我收到很多错误。

升级所有现有依赖项的最佳和快捷方式是什么?

这是angular-cli和angular网站的package.json:

angular2-cli - orginial package.json:

{
  "name": "angular2-projects",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "postinstall": "typings install",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.3",
    "@angular/compiler": "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.3",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.3",
    "@angular/platform-browser": "2.0.0-rc.3",
    "@angular/platform-browser-dynamic": "2.0.0-rc.3",
    "@angular/router": "3.0.0-alpha.8",
    "es6-shim": "0.35.1",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.26",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.9",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "3.11.0",
    "typescript": "1.8.10",
    "typings": "0.8.1"
  }
}
来自angular2网站的

最新更新的angular2依赖关系:

{
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.4",
    "core-js": "^2.4.0",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.6.12",
    "angular2-in-memory-web-api": "0.0.14",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0"
  }
}

2 个答案:

答案 0 :(得分:1)

在packages.json中更新了依赖项后,删除node_modules目录,然后运行“npm install”。这将安装您配置中的所有软件包。

答案 1 :(得分:0)

我不确定问题是否得到了解答,但是为了直接回答,升级package.json文件中所有现有依赖关系的最简单快捷的方法就是去进入包含所述文件(或其任何子代)的文件夹并运行以下内容:

npm update

这将更新所有依赖项(包含dev)到package.json中最新支持的版本并为您安装,随时可以使用。这样做也具有额外的好处,即如果有一些版本的库不能很好地协同工作,那么更新过程将避开它们。

您甚至可以在更新后运行npm outdated以查看您拥有的库,您需要什么以及NPM注册表是否有任何更新。