Suppose that somewhere in my package.json
I have:
"dependencies": {
"bower": "1.0.0",
// zillion other dependencies
}
Is there a way to make npm install only [email protected] from my package.json
? Like so: npm install --only bower
.
My goal is to make npm install
and bower install
run simultaneously.
Use npm list [package-name] to know the specific latest version of an installed package. Use npm install [package-name]@[version-number] to install an older version of a package. Prefix a version number with a caret (^) or a tilde (~) to specify to install the latest minor or patch version, respectively.
Dev Dependencies: In package. json file, there is an object called as dev Dependencies and it consists of all the packages that are used in the project in its development phase and not in the production or testing environment with its version number.
"dependencies" : Packages required by your application in production. "devDependencies" : Packages that are only needed for local development and testing.
As a workaround you may use something like:
$ node -pe "require('./package').dependencies.bower"
// → 1.0.0
$ npm install bower@$(node -pe "require('./package').dependencies.bower")
// npm install [email protected]
// or with jq
$ npm install bower@$(< package.json jq -r '.dependencies.bower')
Where -e/--eval
flag evaluates passed string and -p/--print
prints result of eval.
💡 Please consider other answers as well since this one may be outdated.
As @atalantus noted in comment, the accepted answer doesn't work on newer version of NPM. Working solution for newer versions (verified on NPM 6.13.4) is:
npm install --no-package-lock --no-save [email protected]
This will install bower
and all its dependencies, but prevents installation of anything else you might have in package.json
. It also doesn't create or modify existing package-lock.json
.
From npm documentation:
The
--no-package-lock
argument will prevent npm from creating a package-lock.json file. When running with package-lock's disabled npm will not automatically prune your node modules when installing.
--no-save
: Prevents saving todependencies
.
Combining this with Anton Rudeshko's approach to find out version in package.json
, the final solution is:
VERSION_BOWER=`node -p -e "require('./package.json').dependencies.bower"`
npm install --no-package-lock --no-save bower@"$VERSION_BOWER"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With