1

I have installed some packages with npm globally and some only locally within the folder of my project. When I want to list all locally installed packages in the folder with the command npm list --depth=0 I get a lot of these errors: npm ERR! extraneous. I guess this is because some packages are already installed globally as dependencies. This seems to be no big issue. However, all these errors are pretty annoying. Is there a solution how to hide these?

Hendrik
  • 413
  • 7
  • 17
  • Answered [here](https://stackoverflow.com/questions/22620352/npm-windows-install-globally-results-in-npm-err-extraneous). –  Dec 02 '19 at 16:42
  • Sorry, that is not what I am searching for. The top answer just confirms what I already supposed, that this error is indeed harmless. The second answer doesn't work for me. Another answer suggests to install all packages globally, but this is also not what I desire. Whenever I want to list my local packages in one folder I face dozens of lines of the error. I would like to suppress, hide or filter these out, to see the locally installed packages easily. – Hendrik Dec 02 '19 at 20:35

2 Answers2

2

To suppress npm errors I followed the answer mentioned here: Can I hide or silence "npm ERR!" output when using npm run script?

The command is just extended by the option -s which stands for --silent. This command works now as desired: npm list -s --depth=0

Hendrik
  • 413
  • 7
  • 17
1

The following solution is a bit dirty since it uses an additional grep command, but it perfectly does the job (on Unix-like terminals):

npm list --depth=0 2> >(grep -v "extraneous")

It can be easily generalized to other types of errors or warnings the user wishes to keep hidden.

  • Thanks for that solution. I thought about grep as well, but didn't manage to get working with the output of `npm list`. – Hendrik Dec 03 '19 at 14:41
  • You're welcome! The error messages from Unix commands are sent differently to the standard output, so a simple pipe `|` won't work indeed. –  Dec 03 '19 at 14:45