Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] `process.env.PATH` can be undefined on Windows

Aperta
#108 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

  • #182 di @amtbsl — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
cli

Direzione di ricerca

Start with the repro.js script and reproduce the differing process.env.PATH behavior between the main thread and Worker on Windows. Then trace which's PATH lookup and consider the reported process.env.Path case without changing Unix behavior. Done means which resolves executables in the described Windows worker scenario and the reproduction no longer fails.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Needs Triage
Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

which might fail to resolve the executable on Windows in a threaded context (e.g. a Worker threads) due to PATH being undefined, instead being accessible (only) as Path.

Prior work on this topic in this project exists, starting with #34. It suggests there used to be an alternative lookup, but it was removed for a different reason (as I understand it). The removal happened in #35 / c7a1ac924074d4cf246a3d96f33f7ee350142fcc, stating that:

Reading from a Path environ on Unix systems sometimes causes strange behavior

which is too cryptic for me to understand 😅 Nevertheless, it seems like a fair concern so I think a solution to the problems should take it into account. I'd also like to point out that issues on the Node.js repository on this topic suggest PATH being undefined is 1) known behavior, and 2) not considered a bug.

Running the reproducing script (see below) myself in various settings, I must admit I was not able to reproduce this issue with 100% accuracy. It somehow seems to depend on the terminal in which I run the script, in particular: I can reproduce it using the Windows terminal with both CMD and PowerShell (but not bash, coming with git for Windows) but not with any shell in the VSCode embedded terminal...

Expected Behavior

which does not fail to resolve the executable on Windows if PATH is undefined.

My suggestion would be to consider process.env.Path when process.env.PATH is undefined, possibly conditionally on whether which is running on Windows (per c7a1ac924074d4cf246a3d96f33f7ee350142fcc).

Steps To Reproduce
  1. On windows
  2. With this script (or this project):
    // file: repro.js
    
    import * as process from "node:process";
    import { Worker, isMainThread } from 'node:worker_threads';
    
    if (isMainThread) {
        console.log("[MAIN]", "PATH:", process.env.PATH);
        new Worker("./repro.js");
    } else {
        console.log("[WORK]", "PATH:", process.env.PATH);
    }
    
  3. Run node repro.js from PowerShell or CMD in Windows Terminal (Windows 11) or PowerShell/Command prompt (earlier Windows versions).
  4. Observe that the [MAIN] PATH: prints the full path but the [WORK] PATH: is undefined.
Environment
  • npm: v9.8.1
  • Node: v18.16.1
  • OS: Windows 11 Home (22H2)
  • platform: Virtual Machine (LXC)
Lingua principale
JavaScript
Stelle
352
Fork
55
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/node-which

Tutte le issue di npm/node-which

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.