Blog: NPM, how to install all the dependencies from a package ?
Opened this issue · 0 comments
BensonLiao commented
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:
npm info react-scripts@latest dependencies
list all dependencies for a packageecho $(npm info react-scripts@latest dependencies)
here's a tricky part for valid input stream feed to sedsed -E "s/,|\'|{ | }//g; s/: /@/g"
becausenpm info
will format the result, so we will use regex to clean format$(echo $(npm info react-scripts@latest dependencies) | sed -E "s/,|\'|{ | }//g; s/: /@/g")
another tricky part for valid command argument tonpm i