Home > Software engineering >  Angular version in App-root does not match that of package.json
Angular version in App-root does not match that of package.json

Time:01-25

I downgraded Angular to version 8, everything went fine and in the package.json the version is 8.2.0, but when I look from the console, the version is still 14.0.3.

package.json

{
  "name": "epg",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "prestart": "node aspnetcore-https",
    "start": "run-script-os",
    "start:windows": "ng serve --port 44498 --ssl --ssl-cert %APPDATA%\\ASP.NET\\https\\%npm_package_name%.pem --ssl-key %APPDATA%\\ASP.NET\\https\\%npm_package_name%.key",
    "start:default": "ng serve --port 44498 --ssl --ssl-cert $HOME/.aspnet/https/${npm_package_name}.pem --ssl-key $HOME/.aspnet/https/${npm_package_name}.key",
    "build": "ng build",
    "build:ssr": "ng run epg:server:dev",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.0",
    "@angular/common": "^8.2.0",
    "@angular/compiler": "^8.2.0",
    "@angular/core": "^8.2.0",
    "@angular/forms": "^8.2.0",
    "@angular/platform-browser": "^8.2.0",
    "@angular/platform-browser-dynamic": "^8.2.0",
    "@angular/platform-server": "^8.2.0",
    "@angular/router": "^8.2.0",
    "bootstrap": "^5.1.3",
    "jquery": "^3.6.0",
    "oidc-client": "^1.11.5",
    "popper.js": "^1.16.0",
    "run-script-os": "^1.1.6",
    "rxjs": "~7.5.5",
    "tslib": "^2.4.0",
    "zone.js": "~0.11.6"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^8.2.0",
    "@angular/cli": "^8.2.0",
    "@angular/compiler-cli": "^8.2.0",
    "@types/jasmine": "~4.0.3",
    "@types/jasminewd2": "~2.0.10",
    "@types/node": "^18.0.0",
    "jasmine-core": "~4.2.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.1",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "^2.0.0",
    "typescript": "~4.7.4"
  },
  "overrides": {
    "autoprefixer": "10.4.5"
  },
  "optionalDependencies": {}
}

Angular version with ng version from terminal

Wrong angular version in my console

To downgrade I followed the steps below: npm uninstall -g @angular/cli npm cache clean npm install -g @angular/[email protected] Did I do something wrong? How can I fix this error? Any tip will be appreciated!

CodePudding user response:

You just ran npm install -g @angular/[email protected] that downgraded you angular-cli only.

You missed deleting your existing node_modules folder, removing the package-lock.json if there is one, and you didn't run npm install that will re-install all your packages with specified version.

CodePudding user response:

You made the changes in global npm package but problem is the existing installed packages are still older version you can downgrade by two way

  1. delete the node_modules folder and delete package-lock.json file and run npm install again.
  2. if it's a new setup then regenerate the project with ng new-project name

personally prefer the second solution if you are setup a new project

CodePudding user response:

If you downgraded to lower version make sure to clear node modules and cache. you can try following steps:

  1. Delete node modules using

$rm -rf node_modules

  1. Delete package-lock.json

$ rm -rf package-lock.json

  1. Clear npm cache.

$ npm cache clean -f

And then try to install again using

$npm i

  • Related