Home > Back-end >  npm version in package.json is different from what is showing when running npm -v?
npm version in package.json is different from what is showing when running npm -v?

Time:04-23

my npm version in package file is different than the current version any idea how to unite them or is this a normal behavior ?

 "dependencies": {
    "bcryptjs": "^2.4.3",
    "client": "file:client",
    "config": "^3.3.6",
    "crypto-js": "^4.1.1",
    "express": "^4.17.1",
    "firebase": "^9.6.7",
    "npm": "^8.1.4",
    "ts-node": "^10.5.0",
    "typescript": "^4.4.4"
  },
when i run npm -v 8.5.0

CodePudding user response:

The reason it doesn't update is because you aren't updating npm globally.

So, the npm dependency is redundant.


Normally, you would use the following command to update npm globally.

$ npm install -g npm

But, as you are only specifying it in the local project dependencies, it won't update npm globally.


If you want to update npm globally, you can do so with a script in package.json, as shown below.

{
  "scripts": {
    "global": "npm install -g [email protected]"
  }
}

You can then call it with the following command.

$ npm run global

This will update the npm version globally.


In summary, it is expected behaviour with the way you are doing it currently, but you can update npm globally with a script.

  • Related