læran91
læran91

Reputation: 293

npm is not working properly? 'npm.cmd' failed to run: The system cannot find the file?

enter image description hereI am new to nodejs environment. after installing nodejs in my windows system I tried checking their versions.

node -v is showing v16.7.0 okay.

but npm -v is not working.

I don't know why. I tried changing the environmental variable Path as well but it did not work. below I showed the result after entering npm -v in my windows command promt :

Program 'npm.cmd' failed to run: The system cannot find the file specifiedAt line:1 
char:1
+ npm -v

At line:1 char:1
+ npm -v
+ CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed

so please help me, am stuck here the whole day . pardon me if I do any mistake,Thank you :) ?

Upvotes: 1

Views: 5310

Answers (1)

Edtimer
Edtimer

Reputation: 307

A solution for your issue would be following these instructions.

  1. Open Command Line terminal

  2. Run the following command:

    DISM.exe /Online /Cleanup-Image /RestoreHealth /Source:C:\RepairSource\Windows /LimitAccess

After it finishes successfully run this command:

sfc /scannow
  1. Copy "npm" folder from C:\Program Files\nodejs\node_modules into C:\Users{YourUser}\AppData\Roaming\

  2. then Go to Computer -> Advanced Settings -> Environmental Variables

  3. Add into User "Path" variable new entry: "C:\Program Files\nodejs\node_modules\npm\bin"

  4. Almost there, now add into System "Path" variable 2 new entries:

"C:\Users{YourUser}\AppData\Roaming\npm"

and

"C:\Program Files\nodejs"

  1. Finally run npm-v in a command line to verify npm is working and a version is shown.

Upvotes: 3

Related Questions