简体   繁体   中英

Npm update dont install the last package version?

When i install

npm i nodemon

i get of course always the last version which in this case is: 2.0.2,

but if i install some older version for example npm i nodemon@1.18.11 and after that i try npm update i get the 1.19.4 version but not the last one 2.0.2

like i get with npm install nodemon.

Why npm update is not updatting in this case to 2.0.2 ?

It depends on the version of npm , but npm update don't get a newer, major version of the package if it breaks one or more dependecies. In fact, you're stuck on version 1.x. You can easily use npm i foo to get the very latest version instead with warnings. See https://docs.npmjs.com/cli-commands/update.html for more details, based on the npm version you're using (and how to get the previous behaviour).

It depends on your package.json entries for nodemon.

For example if a module has following dependencies:

{
  "dist-tags": { "latest": "1.2.2" },
  "versions": [
    "1.2.2",
    "1.2.1",
    "1.2.0",
    "1.1.2",
    "1.1.1",
    "1.0.0",
    "0.4.1",
    "0.4.0",
    "0.2.0"
  ]
}

And you speicify '^' in package.json file:

"dependencies": {
  "module": "^1.1.1"  //npm update will install module@1.2.2, because 1.2.2 is latest and 1.2.2 satisfies ^1.1.1
}

Or If your version is specified using '~' tas follows:

"dependencies": {
  "module": "~1.1.1" // npm update will install dep1@1.1.2. Even though the latest tag points to 1.2.2, this version does not satisfy ~1.1.1, which is equivalent to >=1.1.1 <1.2.0. So the highest-sorting version that satisfies ~1.1.1 is used, which is 1.1.2
}

For more understanding you can follow this documentation: https://docs.npmjs.com/cli-commands/update.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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