npx command not found

2020-02-08 22:42发布

问题:

I am working with webpack and I need to execute ./node_modules/webpack/bin/webpack.js using npx. npx webpack would run the webpack binary (./node_modules/webpack/bin/webpack), but each time I execute npx webpack I get bash: npx: command not found.

I am using:

  • node: v9.5.0

  • npm: 5.6.0

  • nvm: 1.1.5

  • webpack: 3.11.0

回答1:

npx should come with npm 5.2+, and you have node 5.6 .. I found that when I install node using nvm for Windows, it doesn't download npx. so just install npx globally:

npm i -g npx


回答2:

if you are using Linux system, use sudo command

sudo npm i -g npx


回答3:

check versions of node, npm, npx as given below. if npx is not installed then use npm i -g npx

node -v
npm -v
npx -v


回答4:

if you are using macOS, use sudo command

sudo npm install -g npx



回答5:

Updating node helped me, whether that be from the command line or just re-downloading it from the web



回答6:

I returned to a system after a while, and even though it had Node 12.x, there was no npx or even npm available. I had installed Node via nvm, so I removed it, reinstalled it and then installed the latest Node LTS. This got me both npm and npx.