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

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

Open
1 task done
ericcornelissen opened this issue Aug 28, 2023 · 0 comments
Open
1 task done

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

ericcornelissen opened this issue Aug 28, 2023 · 0 comments
Labels
Needs Triage needs an initial review

Comments

@ericcornelissen
Copy link

ericcornelissen commented Aug 28, 2023

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 / c7a1ac9, 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 c7a1ac9).

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)
@ericcornelissen ericcornelissen added the Needs Triage needs an initial review label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

1 participant