npm update includes pre-release - node.js

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

Related

npm does not support Node.js v9.0.0

I just upgraded my project to use Node.js v9.0.0. When I start my project using npm, it tells me I should upgrade to a newer Node version, but I believe this is the newest version. I also believe I'm on the newest version of npm (5.5.1).
Do I need to worry about this warning? Is there a good way to resolve the issue?
Here's the full warning:
npm WARN npm npm does not support Node.js v9.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
Now using node v9.0.0 (npm v5.5.1)
I've just upgraded to Node v9 and ran into the same issue. There's a Github issue for this here.
Following the advice to uninstall a global instance of npm has resolved the issue for me, using:
npm uninstall -g npm
With Node 10.6.0 on Windows 10 with Git Bash installed, I did this and all worked well:
1. Launch Git Bash terminal.
2. cd ~/AppData/Roaming
3. rm -rf npm
4. rm -rf npm-cache
5. npm install -g npm#latest
Check version and test on an existing project to verify (cd to project dir)...
6. npm -version
7. npm install
NB: Performing steps 2 through 4 via Windows Explorer could be faster.
9.0.0 is indeed the latest version available at the moment. The reason that NPM shows you this message is because NPM hasn't updated their unsupported.js yet to accept 9.0.0 as a supported version.
I would say that you can probably use it without problems, but if you stumble upon one, know that it's probably caused by a breaking change in Node.js 9.0.0 and will very likely be fixed by the NPM team soon.
npm does not support Node.js v9.1.0
Uninstall did not work for me
npm uninstall -g npm
Node.js v9.1.0 comes bundled with npm v5.5.1. The latest version of npm is also v5.5.1, however, the version bundled with Node.js isn't exactly the same as the original version from npm.
The following is what I needed to do on MacOS
To completely uninstall node + npm, do the following:
1. go to /usr/local/lib and delete any node and node_modules.
2. go to /usr/local/include and delete any node and node_modules directory.
3. download and install node from nodejs.org
Latest update Jan 2018: NPM has released version 5.6.0 to work with this.
How to upgrade npm:
Note if you are using node version 9 you will not be able to upgrade npm directly, since npm does not support version 9, so using nvm, downgrade node to latest stable release, that will make npm work, then use commandnpm install -g npm#latest to upgrade npm.
Install nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash\n
export NVM_DIR="$HOME/.nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Download and use node X version:
nvm install 4.4.2
nvm use 4.4.2
node -v
[sudo] npm install -g npm#5.3.x remove this problem for me. ubuntu 16.10

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 outdated global packages: How to actually update a package?

❯ 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>

Node and NPM versions don't match

The node and npm versions on my mac dont match. How do I downgrade npm to the same version as node?
Node:
$ node -v
$ v0.12.7
NPM:
$ npm -v
$ 2.14.4
npm is a package manager for node.js. They don't have to be the same version. npm also gets updated more frequently than node, so they could not be expected to keep their versions the same
If it helps, you can install any version of NPM. On debian distros, to use npm version 4.5.0 you need to do:
$ curl https://registry.npmjs.org/npm/-/npm-4.5.0.tgz
$ tar -xvzf npm-4.5.0.tgz
$ cd package/
$ [sudo] make install
Their versions are different because they are independent softwares. Their development is not synchronized.
I recommend updating NPM when you can; I'm running npm version 5.2.0
You can easily upgrade your NPM version using npm install -g npm

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