Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does npx look for globally installed packages?

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?

like image 986
Dimitri Kopriwa Avatar asked Jan 02 '23 06:01

Dimitri Kopriwa


1 Answers

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 an npm package runner that executes a <command> (e.g. npm package binaries) by FIRST looking in local node_modules/.bin directory.

So even if we remove it from package.json, as long as binary exists in node_modules/.bin, npx will continue using local.

like image 160
bluelovers Avatar answered Jan 05 '23 16:01

bluelovers