Node JS NPM modules installed but command not recognized
Asked Answered
M

7

77

Node JS and NPM were working well before. Recently I have re-installed the Node JS, NPM and the problem started. After I install a module like an example npm install -g bower, the module gets installed successfully but bower -v gives

'bower' is not recognized as an internal or external command, operable program or batch file.

I have checked the installation path C:\Users\XXXXX\AppData\Roaming\npm\node_modules has all the old installed modules. I have tried to uninstall them and reinstall the modules, but still, I am getting the same error.

Even I have deleted the entire folder and installed all the modules again but the result is the same.

I don't know why I am getting this error after reinstalling NodeJS NPM.

Myrmeco answered 8/6, 2015 at 13:33 Comment(0)
T
99

I had this same problem and fixed it by adding the 'npm' directory to my PATH:

Right-click 'My Computer' and go to 'Properties > Advanced System Settings > Environment Variables'.

Double click on PATH under the 'User variables for Username' section, and add C:\Users\username\AppData\Roaming\npm obviously replacing 'username' with yours. Based on the comments below, you may need to add it to the top/front of your path.

Restart your console window or IDE and you should get a response from the bower command.

Tema answered 8/6, 2015 at 18:3 Comment(5)
you can also run using %APPDATA%\npm. windows will know where to lookGrant
I have already had the path of the npm packages, but I have had to move it on the top of the listProceed
This comment solved it for me. IT should be one of the answers.Vinegary
@ИскренСтаниславов what do you mean by move it to the top of the list? I added the path just like you said but still not getting the results. ThanksWorse
I mean it should be the first path in the PATH list if possible. If not working the problem may be something elseProceed
Q
41

I had the same problem as well but installed it globally so the other answers didn't work.

The nodeJS install may not have added npm to your PATH so it's not recognised globally.

Firstly: To figure out if you installed globally or for current user

If there is an npm folder at C:\Users\(your username)\AppData\Roaming\npm you've installed it for the current user

If there is an npm folder at C:\Program Files\nodejs\node_modules\npm or C:\Program Files(x86)\nodejs\node_modules\npm you've installed it globally for all users to access

Secondly: To add it to the Path

  1. Right-click My Computer
  2. Click on properties down the bottom
  3. Click on Advanced System Settings in the left bar
  4. Click on Environment Variables down the bottom

Now depending on whether you installed globally or for the current user will determine which PATH variable you are updating and with what path location

Local

  1. Double click on PATH under 'user variables' section
  2. Add C:\Users\(your username)\AppData\Roaming\npm without the quotes

Global

  1. Double click on PATH under 'user variables' section
  2. Add C:\Program Files\nodejs without the quotes (or with (x86))

Finally

Close all terminals or programs that aren't able to find npm and open them up again

Qua answered 23/3, 2016 at 2:5 Comment(1)
Thanks.. your global local thing helped me. in my Environment Variables "C:\Program Files\nodejs" was missing. I dont need to add a folder in local user app data.Densify
G
8

Run npm config get prefix and check the correct npm path first and append the output to the PATH using command or adding manually.

npm config get prefix
C:\mydev\tools\npm\npm

set PATH=%PATH%;C:\mydev\tools\npm\npm

Gompers answered 5/11, 2018 at 5:37 Comment(0)
T
4

If the package is successfully installed and still shows the message "'npm' is not recognized as an internal or external command, operable program or batch file."

  1. Click windows start button.
  2. Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
  3. You can run the Node.js Command prompt as administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."
Trig answered 18/7, 2016 at 23:5 Comment(0)
L
1

You should probably check if your node/bin directory is in your PATH variable. Look for it where you've been installing these global modules.

I'm not on windows, so I can't tell you the exact command, but you can check these variables navigating to [Control Panel -> System -> Advanced -> Environment Variables] or something like this.

Lonne answered 8/6, 2015 at 14:5 Comment(4)
What should be the variable name?Myrmeco
This is what I am getting Path=C:\ProgramData\Oracle\Java\javapath; C:\WINDOWS\system32; C:\WINDOWS; C:\WINDOWS\System32\Wbem; C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x 86)\Brackets\command;C:\Program Files (x86)\nodejs\ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSCMyrmeco
Modules are installed in Users\XXX\AppData\Roaming\npm\node_modules Should I add this in the path?Myrmeco
Also check that you've installed the command-line version e.g. to use the 'postcss' module from the command line you need to install the 'postcss-cli' module and not the 'postcss' one :-)Jea
H
1

I had the same issue in Windows

Two solution worked for me

  1. If you are using bash shell, use npm run
    Example : $ npm run ng --version

  2. Use Windows power shell or command prompt

Howl answered 22/6, 2021 at 7:13 Comment(0)
V
0

In my case the npm folder was already in the PATH variable.

If after trying everything else, you also still can't make it work, try to delete the folder from the PATH variable and put it at the beginning of the list.

Vinegary answered 31/10, 2017 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.