npx command not found
Asked Answered
D

15

163

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

Deportee answered 18/4, 2018 at 8:18 Comment(3)
Did you install npx globally?Sect
I was thinking npx command would be made available after webpack version 3.1.0 @omriDeportee
Thanks, npm v5.2.0 has the package incorporated @OmriDeportee
V
260

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

In Linux or Mac OS, if you found any permission related errors use sudo before it.

sudo npm i -g npx
Vhf answered 7/7, 2018 at 14:18 Comment(2)
when i try sudo npm i -g npx it says npm not found but npm by its own works?Involute
@Jonathan most likely you need to sudo apt-get install npm first.Hammack
L
43

if you are using Linux system, use sudo command

sudo npm i -g npx
Lugansk answered 20/2, 2019 at 14:24 Comment(3)
windows ubuntu requires restarting the shellAllenaallenby
For security reasons it's better to install global NPM packages without sudo.Baleful
Either way, I can't seem to get it running from the command line like the repository says. After having run npm install -g npx, typing in npx gives me the command not found. I'm running ubuntu 18.04Impanation
R
15

Remove NodeJs and npm in your system and reinstall it with the following commands:

Uninstallation

sudo apt remove nodejs
sudo apt remove npm

Fresh Installation

sudo apt install nodejs
sudo apt install npm

Configuration optional, in some cases users may face permission errors.

  1. user defined directory where npm will install packages

    mkdir ~/.npm-global
    
  2. configure npm

    npm config set prefix '~/.npm-global'
    
  3. add directory to path

    echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
    
  4. refresh path for the current session

    source ~/.profile
    
  5. cross-check npm and node modules installed successfully in our system

    node -v
    npm -v
    

Installation of npx

sudo npm i -g npx
npx -v

Well done, we are ready to go. Now you can easily use npx anywhere in your system.

Reprovable answered 7/4, 2020 at 15:4 Comment(1)
` nodejs : Conflicts: npm`Boabdil
C
4

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
Contemptuous answered 7/9, 2018 at 13:31 Comment(2)
Like the original question says : "npx : command not found". npx is literally not there.Morbid
Because just like the original poster, I did download npm and I did install it. But, just like in the issue described, npx was "not there" (i.e. not found). The cause was some obscure Linux-related reason. To recap: When it says "command not found" then the issue is that command was not found. So "npx -v" will not work, and it's just reproducing the original problem.Morbid
D
4

if you are using macOS, use sudo command

sudo npm install -g npx

enter image description here

Dynamics answered 22/7, 2019 at 10:36 Comment(0)
E
2

Either delete the path from user variable or correct the right path Restart CMD and it should work.

 (C:\Program Files\nodejs).
Excaudate answered 29/9, 2022 at 7:12 Comment(1)
closing the cmd and opening again worked for me.Krystinakrystle
P
0

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

Pinery answered 18/1, 2019 at 19:30 Comment(0)
K
0

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.

Kriemhild answered 1/9, 2019 at 17:13 Comment(0)
V
0

sudo apt install npm install npm first

(it will take around 177MB node also will get installed along with this cmd) space

Install npx sudo npm i -g npx

Check the version of the installed npm,node,npx (for confirming latest release and installed or no it will show) using nod -v npx -v npm -v

Vesuvius answered 13/3, 2021 at 3:26 Comment(0)
D
0

1. First step: check and install your node version with node -v.

2. second step: check and install your npm version with npm -v. If you still have a problem,might your command is npx create_react_app your_app_name instead of npx create-react-app your_app_name.

Diminution answered 25/4, 2021 at 9:18 Comment(0)
A
0

check node -v,npm -v, npx -v if are you getting output in the terminal but if you are executing these commands inside terminal of any IDE's like VSCODE, ATOM ... etc then reinstall that IDE.

Arbe answered 30/11, 2021 at 17:0 Comment(0)
E
0
  • I went to the documentation of vs-code (mentioned below on recourses section)
  • Initially they ask to check the execution policy by executing Get-ExecutionPolicy on power shell of vs-code -> I got Restricted
  • Next Get-ExecutionPolicy -List to get all of the execution policies with their scorps. And I got the follwing result :/

MachinePolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined

  • Then I rechecked the error which was displayed at the beginning, in vs-code power shell

    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy
    execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".

  • In there too it's mentioned the err is about the current-user

  • So I execute Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

  • And it worked for me. It's pleasure if this would work to you too thanks.

Recourses: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

Energetics answered 16/2, 2022 at 8:54 Comment(0)
G
0

Go To Program Files And Go to Nodejs folder. There will be a powershell file called npm and even npx you can run all npm and npx commands in the respective powershells

Gerik answered 13/8, 2022 at 9:8 Comment(0)
B
0

My issue may be completely unrelated but npx install was borked by my usage of git worktree.

MY NICHE SOLUTION

Remove the git worktrees you'd added. You can see them via git worktree list and then remove them with git worktree remove <pathname>

Bengaline answered 12/9, 2023 at 16:15 Comment(0)
B
-3

try :

sudo su

then

npm i npx 
or 
npi i -g npx

check your npx version by

npx -v
Blab answered 26/6, 2020 at 8:37 Comment(1)
I would recommend using this answer instead as it achieves the same thing in a more secure way.Holmen

© 2022 - 2024 — McMap. All rights reserved.