BensonLiao/blog

Blog: NPM, how to install all the dependencies from a package ?

Opened this issue · 0 comments

In some circumstances, you may encounter a problem when npm i <package-name> not automatically install all the dependencies that package require.

How do we manually install them? (of course not install them per line of command)

We can achieve by using echo, $() and sed,

echo will re-print to standard output to the terminal, $() will turn the command inside the braces to a string variable, and sed will do regex.
So let's try: npm i $(echo $(npm info react-scripts@latest dependencies) | sed -E "s/,|\'|{ | }//g; s/: /@/g")
A detailed about the command:

  1. npm info react-scripts@latest dependencies
    list all dependencies for a package
  2. echo $(npm info react-scripts@latest dependencies)
    here's a tricky part for valid input stream feed to sed
  3. sed -E "s/,|\'|{ | }//g; s/: /@/g"
    because npm info will format the result, so we will use regex to clean format
  4. $(echo $(npm info react-scripts@latest dependencies) | sed -E "s/,|\'|{ | }//g; s/: /@/g")
    another tricky part for valid command argument to npm i