如何在 bash 中抑制 npm WARN 已弃用的消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38281709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to suppress npm WARN deprecated messages in bash
提问by Alexander
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:
我node.js
在 Linux Mint 18.0中安装了多个版本。我使用nvm
. 由于项目依赖性,我需要将版本 0.10 作为默认版本 ( nvm use 0.10
)。因此,每次启动终端时,都会得到以下输出:
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?
如何抑制这些消息?
回答by Andy
You can suppress or quieten NPM via an environment variable:
您可以通过环境变量抑制或静默 NPM:
npm_config_loglevel=silent npm version
This should work in your .bashrc
(or wherever you invoke nvm
):
这应该适用于您.bashrc
(或您调用的任何地方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"
“无声”、“错误”、“警告”、“http”、“信息”、“详细”、“愚蠢”
回答by Sergei Sergeev
You can also add .npmrc file in your project, user directory or globally. The four relevant files are:
您还可以在您的项目、用户目录或全局中添加 .npmrc 文件。四个相关文件是:
- per-project config file (/path/to/my/project/.npmrc)
- per-user config file (~/.npmrc)
- global config file ($PREFIX/etc/npmrc)
- npm builtin config file (/path/to/npm/npmrc)
- 每个项目的配置文件(/path/to/my/project/.npmrc)
- 每个用户的配置文件 (~/.npmrc)
- 全局配置文件 ($PREFIX/etc/npmrc)
- npm 内置配置文件 (/path/to/npm/npmrc)
Example:
例子:
prefix=~/.npm-global
loglevel=error
More information here
更多信息在这里
回答by ErisDS
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
所有功劳归功于 Sam Roberts:https: //github.com/nodejs/node/issues/32876#issuecomment-616709931