11

I have a private dependency on package.json and it should always install the latest version. So instead of the version, it's *.

"dependencies": {
   "@user/package": "*"
}

After the package was updated in npmjs it still installed old version with npm i if I enter exact version number instead of * - it installs a fresh version, which was published like a day ago.

I had a similar issue when the version was updated a minute ago at npmjs but now npmjs cache should be expired & updated with the new version, isn't it?

How can I avoid such issue and always get newest versions for everything with *?

I've tried npm cache verify npm cache clean --force. No luck.

Lukas Liesis
  • 24,652
  • 10
  • 111
  • 109
  • @CodeCaster thanks for the link, probably yes. i had to use npm update to get updates even during initial installation when node_modules did not exist. Which i can't confirm now because i used npm i on each package already to get newest version. – Lukas Liesis Nov 20 '17 at 12:47

2 Answers2

8

you can try to install with the packagename@latest keyword, but as far as i know you can only use this keyword in command line interface with npm install --save.

npm install --save mypackage@latest

after reading the doc here https://docs.npmjs.com/files/package.json i found you can write "latest" instead of any version number in a package.json file. This should do the trick.

Ty Kayn
  • 719
  • 7
  • 24
  • 1
    Thanks but packages are already installed and there are many of them. I'm looking for a solution which would let me have latest versions w/o `npm i` command for ~15 packages each time I open a project on my dev machine. By npm docs `*` instead of version should do it but it doesn't. – Lukas Liesis Nov 20 '17 at 12:44
  • ok, edited my answer, you can use "latest" as a version number apparently. just found that. – Ty Kayn Nov 20 '17 at 12:59
  • 1
    Kauyn `*` is valid version expresion and issue is not about it but about `npm install` command which i had to use `npm update` as answered by CodeCaster, thanks for support – Lukas Liesis Nov 20 '17 at 21:56
5

Even during initial installation of dependencies it's necessary to use npm update instead of npm install.

This question talks more about npm install vs npm update

npm install vs. update - what's the difference?

Conclusion: The only big difference is that an already installed module with fuzzy versioning ...

  • gets ignored by npm install
  • gets updated by npm update

Thanks CodeCaster for a link for correct command. But:

The issue is still there. Most of the time, it works every time. But. Just had another update when npm did not resolve to the newest version. Switching values form * to numbers for now. Seems like a bug for me.

Lukas Liesis
  • 24,652
  • 10
  • 111
  • 109
  • Indeed, I tried to use * and it did not work as expected when I did `npm install`. Having internal components that are published is indeed painful with the versioning. I still haven't seen a leaner way to do it outside of putting a bat file on the root to do the `npm install @latest`. – Kat Lim Ruiz Feb 17 '21 at 15:42