Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM does not work after NODE installation. Program 'npm.cmd' failed to run

Tags:

node.js

npm

Didn't found strict answear of my issue so decided to create a new question.

I'm trying to install new instance of NODE and NPM to my PC. I get installation package from here: https://nodejs.org/en/

After I accepted all steps installation was succesful. To verify what was installed form Power shell I chcecked installed version of the components:

    PS C:\Users\{myUserName}> node -v
    v14.18.1
    PS C:\Users\{myUserName}> npm -v
    Program 'npm.cmd' failed to run: Cannot find fileAt line:1 char:1
    + npm -v
    + ~~~~~~.
    At line:1 char:1
    + npm -v
    + ~~~~~~
        + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
        + FullyQualifiedErrorId : NativeCommandFailed

Also I checked folder: C:\Users{myUserName}\AppData\Roaming\npm

What's intresting this folder in empty. Regarding "Environmental Variables" situation looks as below: User variables - no NODE_PATH declaration System variables - no NODE_PATH declaration, but I have PATH variable that include C:\Program Files\nodejs\

What is more "funny" after I install NODEJS package my CMD stop working and I cannot open it even after few restarts.

Does anyone can suggest any fix for that?

like image 757
Sepcio Avatar asked Jul 07 '26 08:07

Sepcio


1 Answers

Solution step by step:

  1. Open Command Line or Power Shell terminal

  2. Run this command:

    DISM.exe /Online /Cleanup-Image /RestoreHealth /Source:C:\RepairSource\Windows /LimitAccess
    
  3. After it finishes (with success) run this command:

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

  5. Go to Computer -> Advanced Settings -> Environmental Variables

  6. Add into User "Path" variable new entry: "C:\Program Files\nodejs\node_modules\npm\bin" 7.Add into System "Path" variable 2 new entries:

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

    and

    "C:\Program Files\nodejs"
    
  7. Close and open new Command Line/PowerShell terminal and run the command npm -v

  8. If you will see version number - problem solved

like image 196
Sepcio Avatar answered Jul 10 '26 00:07

Sepcio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!