0

This is my path:

PS> $Env:Path
C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;D:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\cmder;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\bin;C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\lib;D:\Program Files\nodejs\;C:\Users\caio1\AppData\Local\Microsoft\WindowsApps;%NVM_HOME%;%NVM_SYMLINK%;C:\Program Files\Java\jdk1.8.0_221\bin;C:\gradle;C:\android-sdk\tools\bin;;C:\Users\caio1\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\caio1\AppData\Roaming\np

Note the following NodJS-related entries, in sequence:

C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\bin
C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\lib
D:\Program Files\nodejs\

But when I type npm -v, Powershell throws this error:

Program 'npm' failed to run: No application is associated with the specified file 
for this operation.
At line:1 char:1
+ npm
+ ~~~.
At line:1 char:1
+ npm
+ ~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed
2
  • As basic question is npm installed in any of the mentioned paths? From my short search default folder should be C:\Program Files\nodejs\node_modules\npm, but you only have D:\Program Files\nodejs in your path variable. Commented Oct 22, 2019 at 14:34
  • @OlafReitz: No, C:\Program Files\nodejs (or equivalent) is the correct PATH entry; npm.cmd is located in that folder. Commented Oct 22, 2019 at 15:17

1 Answer 1

2

tl;dr:

  • Either: Remove the following entries from your $env:PATH variable.
C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\bin
C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\lib
  • Or: Invoke npm as npm.cmd and node as node.exe

Your symptom implies the following:

  • There is a directory in your $env:PATHvariable that contains a file named just npm - without a filename extension...

  • and that directory doesn't also contain files with the same but an executable filename extension, such as .cmd or .exe...

  • and that directory is listed first in $env:PATH, before any other directories that npm files with executable extensions, such as npm.cmd, ...

In a normal NodeJS installation on Windows (installed in $env:ProgramFiles\NodeJs by default), the installation folder contains a npm.cmd batch file for invoking npm, alongside a Unix shell script in the same folder named just npm - without a filename extension.

npm.cmd takes precedence over the extension-less npm, so invoking just npm works as expected.

C:\Users\caio1\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\caiodomingos\.nvm\versions\node\v10.16.3\bin is a directory containing a Linux installation of NodeJs.

In a Linux installation, there is obviously no need for a batch file, so only an extension-less npm Unix shell script is present.

Since this directory comes before your regular NodeJS installation directory (D:\Program Files\nodejs) in your $env:PATH value, PowerShell attempts to invoke the extension-less Unix shell script when you submit npm, which - predictably - fails.

Specifically, because the npm file has no executable file name extension, PowerShell invokes it as a document rather than as an executable, and fails to do so because no application is registered with the Windows (graphical) shell (File Explorer) for opening documents that have no filename extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.