简体   繁体   中英

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?

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> (eg 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM