0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

npxコマンドの優先順位

Posted at

概要

パッケージを一時的にインストールしてコマンドを実行できるnpxコマンドであるが、コマンドの実行には優先順位があるらしいので簡単にまとめる。

疑問

npxコマンドを使っていて疑問に思った。package.jsonにnpxで指定するコマンドのパッケージのバージョン記載がされていてローカルに存在する場合、どっちのバージョンでコマンドが実行されるのだろうか?

答え

ちょっと調べてみた感じ、下記のような優先順位でnpxはコマンドを実行しているらしい。

  1. ローカルのnode_modulesディレクトリを探索して、パッケージが存在したらそのパッケージでコマンドを実行
  2. グローバルを探索して、パッケージが存在したらそのパッケージでコマンドを実行
  3. リモートを探索して、パッケージをインストールして、そのパッケージでコマンドを実行

参考文献

Executes either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for to run.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?