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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:26:09  来源:igfitidea点击:

Is there a way to log the output of npm install command

javascriptnode.jsnpm

提问by EricS

I ran npm installon 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>&1routes stderr to stdout, so everything will output in a single stream.

2>&1stderr 路由到 stdout,因此所有内容都将在单个流中输出。

回答by xx1xx

You may only be interested in the warnings and errors, if so try this:

您可能只对警告和错误感兴趣,如果是这样,请尝试以下操作:

The npm arg is --silent. Or npm config set loglevel warnif 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:

所以你有两个选择:

  1. npm i --silent
  2. npm config set loglevel warnthen npm i
  1. npm i --silent
  2. npm config set loglevel warn然后 npm i

References:

参考:

npm install should be quiet

npm install 应该是安静的

Add option to hide summary output from npm install

添加选项以隐藏 npm install 的摘要输出