无法更新角度版本

Posted

技术标签:

【中文标题】无法更新角度版本【英文标题】:Unable to update angular version 【发布时间】:2020-01-21 06:18:01 【问题描述】:

我正在尝试升级我的 Angular 应用程序。我的 Angular 应用程序的版本是基本应用程序的 4.2.4。 我正在使用Angular Update Guide 中给出的步骤。

根据指南,我必须运行以下命令

npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli

但是当我尝试执行命令时

ng update @angular/cli

它给了我一个错误提示

Error: Cannot update safely because packages have conflicting dependencies. Package @angular/core would need to match both versions "7.2.15" and "8.2.7, which are not compatible.
Cannot update safely because packages have conflicting dependencies. Package @angular/core would need to match both versions "7.2.15" and "8.2.7, which are not compatible.

这就是我的 package.json 的样子


  "name": "stellar",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  ,
  "private": true,
  "dependencies": 
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "angular2-jwt": "^0.2.3",
    "chart.js": "^2.7.2",
    "core-js": "^2.4.1",
    "jquery": "^3.3.1",
    "ng2-archwizard": "^2.1.0",
    "ng2-charts": "^1.6.0",
    "ng2-toastr": "^4.1.2",
    "ng2-validation": "^4.2.0",
    "ngx-bootstrap": "^2.0.5",
    "npm": "^6.2.0",
    "rxjs": "^5.4.2",
    "slick-carousel": "^1.8.1",
    "zone.js": "^0.8.14"
  ,
  "devDependencies": 
    "@angular/cli": "^1.7.4",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/c3": "^0.6.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "c3": "^0.6.2",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "^2.0.5",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.3.3"
  

有人可以帮忙整理一下吗

【问题讨论】:

尝试先升级核心包 尝试运行 ng update --force @federico scamuzzi 我已经完成了版本的升级,但现在遇到了这个问题ERROR in ./node_modules/ngx-bootstrap/bundles/ngx-bootstrap.es2015.js Module not found: Error: Can't resolve 'rxjs/BehaviorSubject' in 'C:\Sameer\Angular Template\DPAngular 8\node_modules\ngx-bootstrap\bundles' 谢谢 @federico scamuzzi 我把它排序添加了 "rxjs-compat": "^6.5.3" 但现在得到类似C:/Sameer/Angular Template/DP Angular 8/node_modules/@angular/core/core"' has no exported member 'AnimationTransitionEvent'. @mxr7350 我把它排序添加了 "rxjs-compat": "^6.5.3" 但现在得到了类似 C:/Sameer/Angular Template/DP Angular 8/node_modules/@angular/core /core"' 没有导出的成员 'AnimationTransitionEvent'。 【参考方案1】:

关注tutorial 或运行以下命令:

#Install npm-check-updates
$ npm i -g npm-check-updates
 
#Run npm-check-updates with -u, will upgrade package.json
$ ncu -u
 
#Install updated packages
$ npm install

#Then run
npm install typescript@3.5.3

【讨论】:

【参考方案2】:

我想你可以关注这个tutorial

或者手动更新你的角度包,像这样的版本

"@angular/core": "~8.2.4"

像这样更新你的 tsconfig.json


  "compileOnSave": false,
  "compilerOptions": 
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext", // add this line
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",// add this line
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  

更新:

安装rxjs-compact解决问题

【讨论】:

我使用的是相同的Tutorial。正如您所说,我将尝试手动更新单个软件包。 @Tony Ngo 谢谢!!! 我已经手动更新了所有相关的包当我运行应用程序时它给出一个错误说An unhandled exception occurred: error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. 更新了你说的方式,但没有改变。但是现在我刚刚将我的打字稿从 "typescript": "~2.3.3" 更新为 "typescript": "^3.5.1" 并摆脱了上述错误。但是现在陷入了一个严重的问题ERROR in ./node_modules/ngx-bootstrap/bundles/ngx-bootstrap.es2015.js Module not found: Error: Can't resolve 'rxjs/BehaviorSubject' in 'C:\Sameer\Angular Template\DPAngular 8\node_modules\ngx-bootstrap\bundles' 我把它排序添加了 "rxjs-compat": "^6.5.3" 但现在得到类似C:/Sameer/Angular Template/DP Angular 8/node_modules/@angular/core/core"' has no exported member 'AnimationTransitionEvent'.

以上是关于无法更新角度版本的主要内容,如果未能解决你的问题,请参考以下文章

无法以角度更新子组件属性

12年的MacBook air无法更新系统,目前版本10.8.5

更新视图角度的值

无法将 pod 更新到最新版本

为啥 AWS amplify 无法识别更新的节点版本?

CocoaPods Firebase 最新版本无法更新