加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

角度cli项目中如何升级角锥2版?

发布时间:2020-12-17 08:12:17 所属栏目:安全 来源:网络整理
导读:我试图将我的角度2项目从2.0.0升级到2.4.1。我明白语义版本化已被采用,因为2.0.0版本和2.x.x版本应该是插件替换。我的经验似乎也表明了。也许我只是不知道我在做什么,但我没有发现这是直截了当的… 尝试1 – 手动升级版本 我天真的第一种方法是手动更新我
我试图将我的角度2项目从2.0.0升级到2.4.1。我明白语义版本化已被采用,因为2.0.0版本和2.x.x版本应该是插件替换。我的经验似乎也表明了。也许我只是不知道我在做什么,但我没有发现这是直截了当的…

尝试1 – 手动升级版本

我天真的第一种方法是手动更新我的@angular依赖关系。你可以参考下面的package.json(更新1)。我进行了这些修改,然后安装了一个npm,我收到了几个警告,当我尝试做一个ng服务时,出现以下错误。

Cannot read property ‘AssetUrl’ of undefined

和我的警告…

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_moduleschokidarnode_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/core@2.4.1 requires a peer of rxjs@^5.0.1 but none was installed.
npm WARN @angular/core@2.4.1 requires a peer of zone.js@^0.7.2 but none was installed.
npm WARN @angular/http@2.4.1 requires a peer of rxjs@^5.0.1 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/compiler@2.0.2 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/platform-server@2.0.2 but none was installed.
npm WARN @angular/compiler-cli@0.6.4 requires a peer of @angular/core@2.0.2 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of @angular/compiler-cli@^2.3.1 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of @angular/tsc-wrapped@^0.5.0 but none was installed.
npm WARN @ngtools/webpack@1.2.1 requires a peer of webpack@^2.1.0-beta.25 but none was installed.

所以我下了兔子洞试图修复这些警告,但我不知道如何修复所有这些警告(例如@ ngtools / webpack),其中一些似乎是相互冲突的。所以我放弃了更新我的角度2版本的手动方法

原来的package.json

{
  "name": "frontend","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","build": "ng build","buildProd": "ng build --env=prod"
  },"private": true,"dependencies": {
    "@angular/common": "2.0.0","@angular/compiler": "2.0.0","@angular/core": "2.0.0","@angular/forms": "2.0.0","@angular/http": "2.0.0","@angular/material": "^2.0.0-alpha.9-experimental-pizza","@angular/platform-browser": "2.0.0","@angular/platform-browser-dynamic": "2.0.0","@angular/router": "3.0.0","@types/google-libphonenumber": "^7.4.8","angular2-datatable": "^0.4.2","apollo-client": "^0.4.22","core-js": "^2.4.1","google-libphonenumber": "^2.0.4","graphql-tag": "^0.1.15","hammerjs": "^2.0.8","ng2-bootstrap": "^1.1.16","rxjs": "5.0.0-beta.12","ts-helpers": "^1.1.2","zone.js": "^0.6.26"
  },"devDependencies": {
    "@types/hammerjs": "^2.0.33","@types/jasmine": "^2.2.30","@types/lodash": "^4.14.39","angular-cli": "1.0.0-beta.16","codelyzer": "~0.0.26","jasmine-core": "2.4.1","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": "3.13.0","typescript": "2.0.2","typings": "1.4.0"
  }
}

更新1的package.json

{
  "name": "frontend","dependencies": {
    "@angular/common": "2.4.1","@angular/compiler": "2.4.1","@angular/core": "2.4.1","@angular/forms": "2.4.1","@angular/http": "2.4.1","@angular/platform-browser": "2.4.1","@angular/platform-browser-dynamic": "2.4.1","rxjs": "5.0.1","zone.js": "^0.7.2"
  },"typings": "1.4.0"
  }
}

尝试2 – 使用npm-check-updates

因为当我尝试选择我的角度依赖关系进行更新时,我最终在需要更新的其他依赖项的蜘蛛网中,我接下来尝试只是更新所有内容。

基于this answer我尝试了以下:

npm i -g npm-check-updates
npm-check-updates -u
npm install

这很好,但是当我尝试服务时,我收到以下错误:

ERROR in AppModule is not an NgModule

使用收集的信息here,我降级了我的版本,这个错误消失了,但是出现了一个新的错误。

ERROR in Error encountered resolving symbol values statically.
Reference to a non-exported function (position 29:10 in the original
.ts file),resolving symbol restPaths in rest-paths.ts,resolving symbol
AppModule in app.module.ts,
resolving symbol AppModule in app.module.ts

我一直在努力解决这些错误,但事实上我遇到了这么多麻烦,就是提高红旗。

有人可以帮忙吗?我采取错误的做法吗?

请注意,我已经看到有关更新推荐卸载角度并重新安装角度的项目的建议,然后执行ng init并覆盖您的配置文件。这对我来说没有效果,因为我已经有了最新的版本。

编辑:
关于最新的角度的声明是不正确的。我有角度cli版本1.0.0-beta.16,而编辑时的最新版本是1.0.0-beta.24。然而,我确实尝试更新我的角度cli并在我现有的项目上运行init。我现在注意到,我没有精确地按照角度描述页面中列出的步骤。我最近跳过了npm安装–save-dev angular-cli @,而且我把所有的node_modules都丢掉了,而不是使用它们概述的rm命令。

UPDATED 04/03/2017:

你现在应该遵循Angular CLI RC migration guide

UPDATED 20/02/2017:

请注意,1.0.0-beta.32有突破性的变化,并删除了ng init和ng更新

拉动请求here规定如下:

BREAKING CHANGE: Removing the ng init & ng update commands because their current implementation causes more problems than it solves.
Update functionality will return to the CLI,until then manual updates
of applications will need done.

angular-cli CHANGELOG.md说明如下:

BREAKING CHANGES
– @angular/cli: Removing the ng init & ng update commands because their current implementation causes more problems than it solves. Once
RC is released,we won’t need to use those to update anymore as the
step will be as simple as installing the latest version of the CLI.

更新17/02/2017:

Angular-cli现已被添加到NPM @angular包中。您现在应该用以下命令替换上述命令 –

全球包装:

npm uninstall -g angular-cli @angular/cli
npm cache clean
npm install -g @angular/cli@latest

本地项目包:

rm -rf node_modules dist # On Windows use rmdir /s /q node_modules dist
npm install --save-dev @angular/cli@latest
npm install
ng init

原始答案

您应该按照GitHub上的README.md的步骤,通过angular-cli更新角度。

他们来了:

更新角度

要将角度更新到新版本,必须更新全局包和项目的本地包。

全球包装:

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest

本地项目包:

rm -rf node_modules dist tmp # On Windows use rmdir /s /q node_modules dist tmp
npm install --save-dev angular-cli@latest
npm install
ng init

运行ng init将检查由ng创建的所有自动生成的文件中的更改,并允许您更新。为每个更改的文件提供四个选择:y(覆盖),n(不覆盖),d(在文件和更新的文件之间显示diff)和h(帮助)。

仔细阅读每个代码文件的差异,并接受更改或在init init完成后手动合并它们。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读