1

After playing around with angular2 and following angular2 guide in thier website I tryied to move to angular2-cli but angular2-cli project doesnt have the most updated dependencies so the compiler give me some errors about some commands in the code.

I want to upgrade all of the dependencies like core,router and more. the most updated router need the most updated core but when I try to do: npm install core -g, i get a lots of errors.

What is the best and fast way to upgrade all the exsisting dependencies?

Here are the package.json of angular-cli and angular website:

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"
  }
}

most updated angular2 dependencies from angular2 website:

{
  "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"
  }
}
4

2 回答 2

1

我不确定问题是否已得到解答,但要给出直接答案,升级文件中所有现有依赖项的最简单和最快的方法package.json是进入包含所述文件(或其任何子文件)的文件夹并运行以下命令:

npm update

这会将所有依赖项(包括开发)更新到您内部的最新支持版本package.json并为您安装它们,准备使用。这样做还有一个额外的好处,即如果存在不能很好地协同工作的库版本,更新过程将避开它们。

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

于 2017-06-21T21:22:40.553 回答
1

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

于 2016-07-08T01:45:15.860 回答