简体   繁体   English

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

[英]Upgrade angular 2 dependencies inside angular2-cli project

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. 在试用了angular2并遵循其网站上的angular2指南之后,我尝试转到angular2-cli,但是angular2-cli项目没有最新的依赖项,因此编译器给我一些关于代码中某些命令的错误。

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. 最新的路由器需要最新的内核,但是当我尝试这样做时:npm install core -g,我会遇到很多错误。

What is the best and fast way to upgrade all the exsisting dependencies? 升级所有现有依赖项的最佳最快方法是什么?

Here are the package.json of angular-cli and angular website: 这是angular-cli和angular网站的package.json:

angular2-cli - orginial package.json: angular2-cli-原始的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: 来自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"
  }
}

Once you've updated your dependencies in the packages.json, delete the node_modules directory, and then run "npm install." 更新packages.json中的依赖关系后,删除node_modules目录,然后运行“ npm install”。 That will install all the packages from your configuration. 这将安装您配置中的所有软件包。

I'm unsure if the question has been answered but to give a direct answer, the easiest and fastest way to upgrade all existing dependencies in a package.json file is to go into the folder that houses said file (or any child thereof) and run the following: 我不确定问题是否已经回答,但可以直接给出答案,升级package.json文件中所有现有依赖项的最简单,最快的方法是进入存放所述文件(或其任何子文件)的文件夹,运行以下命令:

npm update

That will update all dependencies (dev included) to the latest supported versions inside your package.json and install them for you, ready to use. 这会将所有依赖项(包括dev)更新为package.json最新的受支持版本,并为您安装它们,以备使用。 Doing it this way also has the added benefit of meaning that if there are versions of libraries that don't work well together, the update process will steer clear of them. 这样做还有一个好处,即如果某些版本的库不能很好地协同工作,则更新过程将避免使用它们。

You can even run npm outdated after the update to see what libraries you have, what you need and if there are any updates on the NPM registry. 您甚至可以在更新后运行npm outdatednpm outdated ,以查看所需的库,所需的库以及NPM注册表上是否有任何更新。

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

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