Reputation: 24885
I have several version of node.js
installed in Linux Mint 18.0. I manage them using nvm
. Because of a project dependency, I need to have version 0.10 as the default version (nvm use 0.10
). As a result of this, every time I start my terminal, I get the following output:
npm WARN deprecated This version of npm lacks support for important features,
npm WARN deprecated such as scoped packages, offered by the primary npm
npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
npm WARN deprecated latest stable version. To upgrade to npm@2, run:
npm WARN deprecated
npm WARN deprecated npm -g install npm@latest-2
npm WARN deprecated
npm WARN deprecated To upgrade to the latest stable version, run:
npm WARN deprecated
npm WARN deprecated npm -g install npm@latest
npm WARN deprecated
npm WARN deprecated (Depending on how Node.js was installed on your system, you
npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
npm WARN deprecated on Windows, run them from an Administrator prompt.)
npm WARN deprecated
npm WARN deprecated If you're running the version of npm bundled with
npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
npm WARN deprecated will be bundled with a version of npm@2, which has some small
npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
npm WARN deprecated semver behavior.
How do I suppress these messages?
Upvotes: 10
Views: 23296
Reputation: 9295
Update 2021:
(My problem was not an npm WARN deprecated
message but an npm WARN npm
message, but this still applies)
I use npm
v8 on Ubuntu, and I also use nvm
v0.33.11. For personal reasons I have to use node
14 instead of the current version, node 16.
My solution to suppress this:
npm WARN npm npm does not support Node.js v14.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm cannot make any promises that npm will work with this version.
npm WARN npm You can find the latest version at https://nodejs.org/
In file $HOME/.nvm/nvm.sh
in line ~ 2155 I change this
NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
to this
NVM_NPM_PREFIX="$(npm config --loglevel=silent get prefix)"
In addition (perhaps this is optional), I've also changed $HOME/.nvm/.npmrc
where I've added this line
loglevel=silent
as proposed in other answers here in this SO post.
Upvotes: -1
Reputation: 568
You can do this inside your script by removing the event listeners
#!/usr/bin/env node
process.removeAllListeners('warning');
// Do your thang without triggering warnings
All credit to Sam Roberts: https://github.com/nodejs/node/issues/32876#issuecomment-616709931
Upvotes: 3
Reputation: 166
You can also add .npmrc file in your project, user directory or globally. The four relevant files are:
Example:
prefix=~/.npm-global
loglevel=error
More information here
Upvotes: 7
Reputation: 17771
You can suppress or quieten NPM via an environment variable:
npm_config_loglevel=silent npm version
This should work in your .bashrc
(or wherever you invoke nvm
):
npm_config_loglevel=silent nvm use 0.10
Or you can set the environment variable globally
export npm_config_loglevel=silent
Different loglevels can be found here - they are:
"silent", "error", "warn", "http", "info", "verbose", "silly"
Upvotes: 13