I am using Node.js 10.1.0 and npm 6.0.0.
I have installed a package with npm install -g example-package
,
Will npx
look for it? What about npx -p example-package
, does it only look on npm registry?
I am using Node.js 10.1.0 and npm 6.0.0.
I have installed a package with npm install -g example-package
,
Will npx
look for it? What about npx -p example-package
, does it only look on npm registry?
NPX included in NPM 5.2 which looks in your local/node_modules folder to avoid version mismatch with the globally installed package version
If package is not available, npx will automatically install npm packages and it will not be looking for globally installed packages
Check this link for reference - https://blog.scottlogic.com/2018/04/05/npx-the-npm-package-runner.html
npx
install the package? does it install at global scope or local to the project? –
Metamer In Node.js v10
(npm@6
and probably later);
npx
will look global binaries, after looking locally.
But we can use -p
option to prevent looking globally, like:
npx -p name_of_module
Note
npx
is annpm
package runner that executes a<command>
(e.g. npm package binaries) by FIRST looking in localnode_modules/.bin
directory.So even if we remove it from
package.json
, as long as binary exists innode_modules/.bin
,npx
will continue using local.
npx -p jest --version
gives me 6.14.15 which is my current npm version, not jest version. npx jest --version
gives me 27.3.1 which is accurate. –
Perdurable -p
opton we need to follow this format: npx [options] [-p|--package <package>]... <command> [command-arg]...
. So, it looks like npx -p jest jest --version
will do the right thing. I guess this is to support packages where the command name is not the same as the package name (e.g. typescript
package has tsc
as main command) –
Unconditioned NPX included in NPM 5.2 which looks in your local/node_modules folder to avoid version mismatch with the globally installed package version
If package is not available, npx will automatically install npm packages and it will not be looking for globally installed packages
Check this link for reference - https://blog.scottlogic.com/2018/04/05/npx-the-npm-package-runner.html
npx
install the package? does it install at global scope or local to the project? –
Metamer © 2022 - 2024 — McMap. All rights reserved.
npx
is that you don't need to use-g
anymore. – Virgate