最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does npx look for globally installed packages? - Stack Overflow

programmeradmin1浏览0评论

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?

Share Improve this question edited Jun 12, 2018 at 6:36 Ry- 225k56 gold badges489 silver badges497 bronze badges asked Jun 11, 2018 at 18:55 Dimitri KopriwaDimitri Kopriwa 14.4k32 gold badges112 silver badges230 bronze badges 3
  • npx looks in local /node_modules folder for the example-package and if it is not available , it downloads and runs but it doesnt look for global , as it is kind of replacement for global – Naga Sai A Commented Jun 11, 2018 at 19:03
  • chekc this link for more details - blog.scottlogic.com/2018/04/05/npx-the-npm-package-runner.html – Naga Sai A Commented Jun 11, 2018 at 19:03
  • The benefit of npx is that you don't need to use -g anymore. – zero298 Commented Jun 11, 2018 at 19:05
Add a comment  | 

2 Answers 2

Reset to default 12

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.

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

发布评论

评论列表(0)

  1. 暂无评论