Skip to content

C:\Program Files\nodejs\npm command not found - suddenly stops for IDE and Windows Terminal, but not WSL Bash.exe. (on same system)  #51110

Open
@iPoetDev

Description

@iPoetDev

Version

18.15, 20.10

Platform

Microsoft Windows NT 11.0.22621.0 x64

Subsystem

NPM / NPM.cmd

What steps will reproduce the bug?

Yesterday: npm install works and packages installed. (Environmental variables as-is)
Today: Running npm install generates Unknown command: "C:\Program Files\nodejs\npm" unexpectedly.
System change: ordering of environmental variables for Git/bin/bash v system32/bash.exe (unrelated) for another project (since removed in further troubleshooting).

Step 1: Attempt 1: Simple attempt

  • I uninstalled NodeJs LTS v18 and upgraded to NodeJS and rebooted
  • Used BulkCrapUninstaller to uninstall/remove traces from registry.

Step 2: Attempt 2: Clean Un-/Re- install: Git, Node LTS v20

  • Removed Git 2.43 and Nodev20
  • Scanned the registry for any npm or node references
  • Removed all references in sysdm.cpl (runas:/ Admin) for Environmental Variables
    Then:
  • Rebooted
  • Installed Git, then NodeJs under Administrator runas/ elevated priviledges.
  • Ran the commands as below.

Configured the following

  • Git: c:\Program Files\git
  • Node: c:\Program Files\nodejs
    • AppData : c:\AppData\Roaming\npm
    • Manually copied the c:\Program Files\nodejs\node_modules\npm ==> c:\AppData\Roaming\npm
  • System Environments Variables and User Environmental Variables (see below)

How often does it reproduce? Is there a required condition?

node -v generates a version output to stdout: v20.10.0
npm -v generates a version output to stdout: v10.2.3

  • but on Windows
    npm help => Unknown command: "C:\Program Files\nodejs\npm"
    npm install => Unknown command: "C:\Program Files\nodejs\npm" or any oither
  • but in WSL2 (Ubuntu): C:\Windows\System32\Bash.exe
    npm help => works StdOut
    npm install => works StdOut

What is the expected behavior? Why is that the expected behavior?

npm commands should execute in Windows 11 from within Windows Terminal (Powershellv7)

However, I have WSL installed and from C:\Windows\System32\bash.exe it runs as expected. WSL was installed over 7 days ago and npm ran as expected and is running as expected..

I use Jetbrains IDEs and use their Run Configurations heavily and these IDE rely on C:\Program Files\nodejs\npm.cmd. (Actually I found out this issue happen that previously running scripts stopped running in this interface). I rely on these IDE Run Configs for current projects.

The script npm in C:\Program Files\nodejs is not being detected.

What do you see instead?

Running npm install or npm help generates Unknown command: "C:\Program Files\nodejs\npm"

  • Irrespective of Reinstalling NodeJs several times.
  • Configuring the Environmental Vars and
    • Ordered the nodejs and npm to top of paths
    • Added additional USER custom vars
      • NODE_PATH: directory level
        • C:\Program Files\nodejs
      • NODE_EXE: file level
        • C:\Program Files\nodejs\node.exe
      • NPM_PATH: directory level
        • C:\Program Files\nodejs
        • C:\Program Files\nodejs\node_modules
        • C:\Program Files\nodejs\node_modules\npm\bin
      • NODE_EXE: files level
        • C:\Program Files\nodejs\npm.cmd
        • C:\Program Files\nodejs\npm
        • C:\Program Files\nodejs\npx
        • C:\Program Files\nodejs\npx.cmd

Exceptionally by re-ordering (a failed smoke test)

Path=C:\Program Files\nodejs\node_modules\npm\bin;
C:\Program Files\nodejs\;
C:\Users\`$User`\AppData\Roaming\npm;

Generates : such suggest that the node/npm is detecting the package at some entry point but refuses to use the npm script..

npm help
node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'C:\Program Files (x86)\Nodist\bin\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.10.0
  • Windows Compatibility troubleshooter.
  • Autopatchng my user/system installed apps using WinGetUI 2.1.2

I have spent 4 to 5 hours trying to fix.

Additional information

IDE:

  • Webstorm: 2023.2.3
  • PyCharm: 2023.2.3

Environmental Variables
$User is replacer for actual user path. Line breaks added for readability but remove for actual.
System Path:

Path=C:\Program Files\nodejs\;
C:\Program Files\nodejs\node_modules\npm\bin;
C:\Users\`$User`\AppData\Roaming\npm;
C:\Program Files\Git\cmd;
C:\Python312\;
C:\Users\`$User`\scoop\shims;
C:\ProgramData\chocolatey\bin;
C:\Python312\Scripts\;C:\WINDOWS;
C:\WINDOWS\System32\OpenSSH\;
C:\WINDOWS\system32;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Users\`$User`\AppData\Local\Microsoft\WinGet\Links;
C:\Program Files\Microsoft\Web Platform Installer\;
C:\Program Files\dotnet\;C:\Program Files\PowerShell\7\;
C:\Program Files (x86)\Nodist\bin;

User Path:

Path=C:\Users\`$User`\AppData\Roaming\npm;
C:\Users\`$User`\scoop\shims;
C:\Users\`$User`\AppData\Local\Microsoft\WindowsApps;
C:\Users\`$User`\AppData\Local\JetBrains\Toolbox\scripts;
C:\Users\`$User`\AppData\Local\Microsoft\WinGet\Links;
C:\Users\`$User`\AppData\Local\Programs\WingetUI\choco-cli\lib;
C:\Users\`$User`\AppData\Local\Programs\WingetUI\choco-cli\lib\make\tools\install\bin;
C:\Users\`$User`\AppData\Local\Microsoft\WinGet\Links\wget.exe;
C:\Python312;

MS Security Definitions Updates

- Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.403.260.0) - Current Channel (Broad): ): Installed 10/12/23
- Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.403.228.0) - Current Channel (Broad): Installed 09/12/23

Can provide a Belarc Advisory Inventory by private means.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    npmIssues and PRs related to the npm client dependency or the npm registry.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions