npm outdated global packages: How to actually update a package? - node.js

❯ npm outdated -g
Package Current Wanted Latest Location
eslint 3.11.1 3.11.1 3.15.0
eslint-plugin-react 3.0.0 6.9.0 6.9.0
flow-bin 0.35.0 0.39.0 0.39.0
grunt-cli 0.1.13 1.2.0 1.2.0
gulp 3.9.0 3.9.1 3.9.1
jshint 2.8.0 2.9.4 2.9.4
npm 3.8.6 4.3.0 4.2.0
uglify-js 2.7.0 2.7.5 2.7.5
Wondering why my eslint won't update. npm upgrade -g -dd eslint shows me
npm verb outdated not updating eslint because it's currently at the maximum version that matches its specified semver range
Which led me to try outdated, but either way, global package.json isn't a thing that exists. So why am I limited to 3.11??
According to npmjs doc,
If there's no available semver range (i.e. you're running npm outdated
--global, or the package isn't included in package.json), then wanted shows the currently-installed version.
This simply doesn't make any sense.

Following the de-facto workflow of npm, we remove and reinstall the package.
npm remove -g eslint && npm install -g eslint
npm, why are you so bad?

To update global packages to the 'Latest' version:
npx npm-check --global --update
That will update global packages to the 'Latest' version*. More information is available about npm-check, including the ability to update without prompting, exclude packages, etc.
Conversely, npm update -g only updates global packages to the 'Wanted' version shown by npm outdated --global, as globally installed packages are treated as if they are installed with a caret semver range specified.
Lastly, if you happen to want to update (install) a package to a version other than 'Latest' or 'Wanted': npm install --global <pkg>#<version>

Related

Cannot update from Gatsby 2.12.78 to 3.X globally

I have tried running npm i -g gatsby-cli and sudo npm i -g gatsby-cli but when I run gatsby --version it still says 2.12.78 even though it also says "Update available 2.12.78 → 3.10.0 | Run npm i -g gatsby-cli to update"
These are my package versions:
npm version: 7.19.1
node version: v16.5.0
Gatsby CLI version: 2.12.78
You just need to follow the migration guide:
npm install gatsby#latest
All gatsby-* should be upgraded too, but without updating the global Gatsby package you can't update the related ones. Check them by:
npm outdated

Cannot upgrade to jhipster 5.3.4

After "yarn global upgrade generator-jhipster", the version is 4.14.5 instead of latest version 5.3.4. why?
My node version is 8.11.1, yarn is 1.3.2.
2 possibilities:
when you run jhipster --version it prints local version (from local node_modules folder) if your are in a generated project, this enables projects to isolate from each others. In this case you must upgrade the project with jhipster upgrade
when you are not in a generated project, jhipster --version prints globally installed version and it probably means that you have installed jhipster twice (once with yarn and once with npm)
Usually the fix to double global installation is to uninstall from npm and yarn then reinstall with one or the other:
Remove from both yarn and npm
yarn global remove generator-jhipster
npm uninstall -g generator-jhipster
Install with just npm
npm install -g generator-jhipster
Since JHipster 5.3.0 npm is now the default client package manager, instead of Yarn.
Check version
jhipster --version
Using JHipster version installed globally
5.3.4
Right tick answer didn't work for me, which describe following steps:
yarn global remove generator-jhipster
npm uninstall -g generator-jhipster
npm install -g generator-jhipster
In my case I removed all mode modules & node itself, then fresh installation of jhipster worked for me.

Downgrade npm to an older version

I tried updating npm to see if it would solve some dependency problems we were having, and now I want to downgrade to the version the rest of the development team is using. How can I install an older version?
I updated npm according to the instructions on the About npm CLI versions:
The latest release of npm
The latest release of npm is the most recent stable version. When you install Node.js, npm is automatically installed. However, npm is released more frequently than Node.js, so to install the latest stable version of npm, on the command line, run:
npm install npm#latest -g
Just replace #latest with the version number you want to downgrade to. I wanted to downgrade to version 3.10.10, so I used this command:
npm install -g npm#3.10.10
If you're not sure which version you should use, look at the version history. For example, you can see that 3.10.10 is the latest version of npm 3.
Just need to add version of which you want
upgrade or downgrade
npm install -g npm#version
Example if you want to downgrade from npm 5.6.0 to 4.6.1 then,
npm install -g npm#4.6.1
It is tested on linux
npm install -g npm#4
This will install the latest version on the major release 4, so no need to specify version number. Replace 4 with whatever major release you want.
Even I run npm install -g npm#4, it is not ok for me.
Finally, I download and install the old node.js version.
https://nodejs.org/download/release/v7.10.1/
It is npm version 4.
You can choose any version here
https://nodejs.org/download/release/

npm update includes pre-release

There is a package, which has a latest version of 2.1.3, and a pre-release version of 3.0.0-rc.7. When I run npm install package -g, 2.1.3 is installed. When I run npm update -g, it updates to the pre-release (which I had installed previously, but removed later). Does npm keep a record of the pre-release being the latest?
$ package -v
2.1.3
$ sudo npm update -g package
$ package -v
3.0.0-rc.7
$ sudo npm remove package -g
$ sudo npm install package -g
$ package -v
2.1.3
The package registry gives "latest":"2.1.3" and "pre":"3.0.0-rc.7". I'm using npm 1.4.13 and node 0.10.28.
Yes, an npm repository can keep several different dist-tags, with latest being the default when publishing and installing. See npm dist-tag documentation.
The semver concept of a pre-release identifier and the npm concept of a non-default dist-tag are distinct, but it is probably a best-practice use them together if a package author chooses to npm publish any pre-release versions. For example, when publishing a release-candidate, it might be appropriate to tag it with next. For a more complex example, see the output from this command:
C:> npm dist-tag ls npm
3.x-latest: 3.9.6
3.x-next: 3.10.1
latest-1: 1.4.29
latest-2: 2.15.6
latest: 3.9.6
lts: 2.15.6
next-2: 2.15.8
next: 3.10.1
v3.x-latest: 3.9.6
v3.x-next: 3.10.1

How to install a previous exact version of a NPM package?

I used nvm to download node v0.4.10 and installed npm to work with that version of node.
I am trying to install express using
npm install express -g
and I get an error that express requires node version >= 0.5.0.
Well, this is odd, since I am following the directions for a node+express+mongodb tutorial here that used node v0.4.10, so I am assuming express is/was available to node v0.4.10. If my assumption is correct, how do I tell npm to fetch a version that would work with my setup?
If you have to install an older version of a package, just specify it
npm install <package>#<version>
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view <package> versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
It's quite easy. Just write this, for example:
npm install -g npm#4.6.1
Or:
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
First remove old version, then run literally the following:
npm install express#3.X
or
npm install express#4.X
and for stable or recent
npm install -g npm#latest // For the last stable version
npm install -g npm#next // For the most recent release
In my opinion that is easiest and fastest way:
$ npm -v
4.2.0
$ npm install -g npm#latest-3
...
$ npm -v
3.10.10
you can update your npm package by using this command:
npm install <package_name>#<version_number>
example:
npm install yargs#12.0.2
You can use the following command to install a previous version of an npm package:
npm install packagename#version
I have a general way to solve this type of problems, which could be helpful too, especially when cloning repositories to run them locally, but requires a little more analysis of the versions.
With the package npm-check-updates I verify the versions of the packages (according to the package.json file) that are not declared in their latest available versions, as shown in the figure (https://www.npmjs.com/package/npm-check-updates):
With this information we can verify the update status of the different packages and make decisions as to which packages to upgrade / degrade and which ones do not.
Assuming that we decided to update all the packages as they are listed, we can use the ncu -u command which only modifies your package.json file. Run npm install to update your installed packages and package-lock.json.
Then, depending on the requirements of the repository, we can refine what is needed, installing the specific versions with
npm view <package> versions and npm install <package>#<version>
The easiest way I found: add package name with the version in package.json and then run npm install
"next-seo": "^5.4.0",
"next-themes": "^0.1.1",
"nextjs-progressbar": "^0.0.14",
If you have to install an older version of a package, just specify it
npm install #
For example: npm install express#3.0.0
You can also add the --save flag to that command to add it to your package.json dependencies, or --save --save-exact flags if you want that exact version specified in your package.json dependencies.
The install command is documented here: https://docs.npmjs.com/cli/install
If you're not sure what versions of a package are available, you can use:
npm view versions
And npm view can be used for viewing other things about a package too. https://docs.npmjs.com/cli/view
Use npm config set save-exact=true if you want to install the exact version

Resources