Javascript 有没有办法记录 npm install 命令的输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32961726/
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
Is there a way to log the output of npm install command
提问by EricS
I ran npm install
on a project and it gives a number of errors and warnings that I want to catch, but the output is too long and being cut off so I can't view the full list in the terminal.
我运行npm install
了一个项目,它给出了许多我想捕获的错误和警告,但输出太长并且被切断,因此我无法在终端中查看完整列表。
I tried redirect it to a file but the output is still being written to the terminal and I still get an output file which only list the dependency trees.
我尝试将它重定向到一个文件,但输出仍在写入终端,我仍然得到一个只列出依赖树的输出文件。
I also tried to pipe it to less in linux but it still run through many screens until stopped for continue.
我还尝试在 linux 中将其通过管道传输到 less,但它仍会运行许多屏幕,直到停止继续。
I checked npm doc and it doesn't seem to have log functionality, what I want is to be able to log the exact output in a file, how can I do it?
我检查了 npm doc,它似乎没有日志功能,我想要的是能够在文件中记录确切的输出,我该怎么做?
回答by keithmo
npm install 2>&1 | tee log.txt
npm install 2>&1 | tee log.txt
The 2>&1
routes stderr to stdout, so everything will output in a single stream.
将2>&1
stderr 路由到 stdout,因此所有内容都将在单个流中输出。
回答by xx1xx
You may only be interested in the warnings and errors, if so try this:
您可能只对警告和错误感兴趣,如果是这样,请尝试以下操作:
The npm arg is
--silent
. Ornpm config set loglevel warn
if you want to only print warnings and errors. Or you can pipe it to/dev/null
.
npm 参数是
--silent
. 或者,npm config set loglevel warn
如果您只想打印警告和错误。或者您可以将其通过管道传输到/dev/null
.
so you have 2 options:
所以你有两个选择:
npm i --silent
npm config set loglevel warn
thennpm i
npm i --silent
npm config set loglevel warn
然后npm i
References:
参考: