Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

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?

like image 442
EricS Avatar asked Oct 06 '15 04:10

EricS


People also ask

Where are npm install logs?

The default location of the logs directory is a directory named _logs inside the npm cache. This can be changed with the logs-dir config option.

How do I view npm logs?

To find your . npm directory, use npm config get cache . If you use a CI environment, your logs are likely located elsewhere. For example, in Travis CI, you can find them in the /home/travis/build directory.

What is npm verbose?

Example usage: npm install ionic --loglevel verbose . Running the npm commands like this, shows the logs in realtime and saves the logs to the directory its running within. For permanent solution, just edit the global npm configuration. To do this, run npm config edit command and add loglevel=verbose .

How do you check if npm has been installed?

To see if NPM is installed, type npm -v in Terminal. This should print NPM's version number so you'll see something like this 1.4.

How do I generate NPM debug logs?

If you need to generate a npm-debug.log file, you can run one of these commands. You can find the npm-debug.log file in your .npm directory. To find your .npm directory, use npm config get cache. If you use a CI environment, your logs are likely located elsewhere.

Where are NPM logs written?

All logs are written to a debug log, with the path to that file printed if the execution of a command fails. The log levels listed above have various corresponding aliases, including: The npm CLI began hiding the output of lifecycle scripts for npm install as of v7.

Why can't I see the output of NPM install scripts?

The npm CLI began hiding the output of lifecycle scripts for npm install as of v7. Notably, this means you will not see logs/output from packages that may be using "install scripts" to display information back to you or from your own project's scripts defined in package.json.

What happens when NPM fails to install or publish a package?

When a package fails to install or publish, the npm CLI will generate an npm-debug.log file. This log file can help you figure out what went wrong. If you need to generate a npm-debug.log file, you can run one of these commands.


2 Answers

npm install 2>&1 | tee log.txt

The 2>&1 routes stderr to stdout, so everything will output in a single stream.

like image 115
keithmo Avatar answered Oct 16 '22 18:10

keithmo


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

The npm arg is --silent. Or npm config set loglevel warn if you want to only print warnings and errors. Or you can pipe it to /dev/null.

so you have 2 options:

  1. npm i --silent
  2. npm config set loglevel warn then npm i

References:

npm install should be quiet

Add option to hide summary output from npm install

like image 22
xx1xx Avatar answered Oct 16 '22 19:10

xx1xx