X Tutup
The Wayback Machine - https://web.archive.org/web/20231224182835/https://github.com/nodejs/node/issues/51110
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Dec 10, 2023 · 5 comments
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. windows Issues and PRs related to the Windows platform.

Comments

@iPoetDev
Copy link

iPoetDev commented Dec 10, 2023

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.

@iPoetDev iPoetDev changed the title C:\Program Files\nodejs\npm command not found - suddenly stops for IDE and Windows Terminal, but not WSL Bash.exe. C:\Program Files\nodejs\npm command not found - suddenly stops for IDE and Windows Terminal, but not WSL Bash.exe. (on same system) Dec 10, 2023
@iPoetDev
Copy link
Author

iPoetDev commented Dec 10, 2023

Update: Further testing under WindowsTerminal + conhost's cmd.exe and npm install works when

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

But the behaviour inconsistent AS same command fails in Windows Terminal/Powershell

Further testing: in IDE for further behaviours on going.Need IDE to behave before issue and run configs to behave as expected.

In Webstorm:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

npm install
Could not determine Node.js install directory
PS D:\Code\CodeInstitute\examples\AlpineTicTacToe>  

@iPoetDev
Copy link
Author

iPoetDev commented Dec 10, 2023

And Node is accessing the UAC mechanism when IDE runs (under runas/ Administrator?). which send Webstorm into a UAC loop.

@iPoetDev
Copy link
Author

Similar, but not the same profile
#29287

@iPoetDev
Copy link
Author

iPoetDev commented Dec 12, 2023

Would using docker on Windows be a workaround verses using Windows as the native host/Dev container for npm globally with WSL co installed? I think the WSL Node/NPM install is hijacking the Windows node/npm install?

I think, given that I did on first run/execution the WSL Bash.exe (Windows\System32\Bash.exe) from a Window context before this npm concern, there is a side effect of WSL version of node/nom on Windows hijacking the priority execution of the Windows node/npm from the Window kernel over the WSL kernel on Windows.

Now npm runs inside the WSL Bash.exe and not from any other window's shell where command is not found.

@marco-ippolito marco-ippolito added windows Issues and PRs related to the Windows platform. npm Issues and PRs related to the npm client dependency or the npm registry. labels Dec 15, 2023
@marco-ippolito
Copy link
Contributor

cc @nodejs/npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
npm Issues and PRs related to the npm client dependency or the npm registry. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup