简体   繁体   English

使用 Angular cli 创建新的 Angular 项目 - @angular/cli 和 @angular/core 在 package.json 中显示不同的版本

[英]Creating new angular project using angular cli - @angular/cli and @angular/core show different versions in package.json

Angular beginner here. Angular 初学者在这里。 Currently held assumption - when creating a new angular project, versions of packages in package.json should match those in npmjs website.当前持有的假设 - 当创建一个新的 Angular 项目时,package.json 中的包版本应该与 npmjs 网站中的包版本匹配。

npm list -g shows the following npm list -g显示如下

/usr/local/lib
├── @angular/cli@14.0.5
├── corepack@0.10.0
└── npm@8.13.2

Upon creating a new angular app using ng new demo , inside package.json, @angular/cli version is 14.0.5 - but @angular/core version is 14.0.0使用ng new demo创建新的 Angular 应用程序后,在 package.json 中,@angular/cli 版本为 14.0.5 - 但 @angular/core 版本为 14.0.0

package.json包.json

{
  "name": "demo",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.0.0",
    "@angular/common": "^14.0.0",
    "@angular/compiler": "^14.0.0",
    "@angular/core": "^14.0.0",
    "@angular/forms": "^14.0.0",
    "@angular/platform-browser": "^14.0.0",
    "@angular/platform-browser-dynamic": "^14.0.0",
    "@angular/router": "^14.0.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.0.5",
    "@angular/cli": "~14.0.5",
    "@angular/compiler-cli": "^14.0.0",
    "@types/jasmine": "~4.0.0",
    "jasmine-core": "~4.1.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.7.2"
  }
}

ng update @angular/core shows Package '@angular/core' is already up to date. ng update @angular/core显示Package '@angular/core' is already up to date. But npm install @angular/core bumps the version to 14.0.5 in package.json file.但是npm install @angular/core在 package.json 文件中将版本提高到 14.0.5。

Why doesn't the latest cli install latest @angular/<other packages> ?为什么最新的 cli 不安装最新的@angular/<other packages>

They are doing slightly different things though the outcome is similar.尽管结果相似,但他们做的事情略有不同。 Basically ng update may also check for schematics to decide if based on compatibility, it would actually bump the version - or not.基本上ng update还可以检查原理图以确定是否基于兼容性,它实际上会影响版本 - 或不。 npm i will just do it, no checks. npm i只会做,不检查。 ng is done with Angular CLI and npm with npm CLI so their different in their behavior because they are different things. ng使用 Angular CLI 完成, npm使用 npm CLI 完成,因此它们的行为不同,因为它们是不同的东西。 https://angular.io/guide/schematics#update-schematics https://angular.io/guide/schematics#update-schematics

If you were on "@angular/core": "13.0.0" while everything else was at 14 and did ng update most likely you will be bumped to 14 with the core.如果你在"@angular/core": "13.0.0"而其他一切都在 14 并且ng update很可能你会被核心撞到 14。 But in your case, it was best decided to stay on 14.0.0 and ignore the minor version 14.0.5 .但在您的情况下,最好决定留在14.0.0并忽略次要版本14.0.5

Upgrading Angular stuff with ng update is a good idea, because of schematics.由于原理图,使用ng update升级 Angular 的东西是个好主意。 Other 3rd party packages probably don't have schematics so well have to make do with npm i .其他 3rd 方包可能没有原理图,所以必须使用npm i

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

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