0

Getting the following error while checking for npm version using Windows PowerShell.

Program 'npm.cmd' failed to run: The specified executable is not a valid application for this OS platform.At line:1
char:1
+ npm -v
+ ~~~~~~.
At line:1 char:1
+ npm -v
+ ~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

Can someone help me with this?

tdy
  • 36,675
  • 19
  • 86
  • 83
  • The nodejs installer will not automatically add the installation directory to the `PATH`, so anything command line will not know where to look. Find the directory containing npm (usually under `/Program Files/NodeJS/...`), and add it manually to the PATH. – Rogue Mar 28 '21 at 05:53
  • I tried creating new environment variables like this... NODESJS_HOME= C:\Program Files\nodejs NODESJS_MODULES=C:\Program Files\nodejs\node_modules NODEJS_NPM =C:\Program Files\nodejs\node_modules\npm Can this cause any problem? – Ashish Sai Mar 28 '21 at 06:07
  • That's well and good, but `PATH` is the one that matter here. – Rogue Mar 28 '21 at 06:08
  • tried addind this path C:\Program Files\nodejs\node_modules\npm\bin under PATH in environment variable, but still getting the same error. I think this error is OS related. – Ashish Sai Mar 28 '21 at 06:45
  • Unfortunately just user error (and lack of a proper installer): you need to add the folder that _contains_ `npm` (and in effect, contains `node_modules`). AKA you should be adding: `C:\Program Files\nodejs\\` – Rogue Mar 28 '21 at 17:48

0 Answers0