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

process.env.PWD is not set on Windows 10 when using powershell #1881

Closed
Raiondesu opened this issue Apr 24, 2019 · 6 comments
Closed

process.env.PWD is not set on Windows 10 when using powershell #1881

Raiondesu opened this issue Apr 24, 2019 · 6 comments

Comments

@Raiondesu
Copy link

  • Version: v8.12.0
  • Platform: Windows 10 Education 1803; Build 17134.706
  • Subsystem: Process

Description

process.env.PWD logs undefined on Windows 10 PC using batch/powershell. Issue does not seem to be present when using bash on windows (either GitBash or using an Ubuntu subsystem).

Reproduction

Just do

> node
> process.env.PWD

( yields undefined )
on a Windows 10 PC.

If cannot reproduce - proceed to npm i https://github.com/ke-mantha/mantha.git#test in an empty directory.

@bnoordhuis
Copy link
Member

Why are you reporting that here? process.env just reflects the environment that node was started in. If PWD wasn't present, then it won't be set in process.env either.

I'm closing this out. Let me know if there is reason to reopen.

@Raiondesu
Copy link
Author

Sorry, I didn't know where else to post this. Also, there are multiple other issues regarding process.env in this repo.

And, btw, aren't some env variables set directly by node and npm?

If no - is there a way to consistently set PWD correctly outside of bash?

@addaleax addaleax transferred this issue from nodejs/node Apr 24, 2019
@addaleax
Copy link
Member

@Raiondesu I’ve moved this issue to nodejs/help, that should be a good place for this – it doesn’t appear to be an issue with node itself, though.

And, btw, aren't some env variables set directly by node and npm?

Some are used internally by node (e.g. for communicating with child processes), but generally, node doesn’t set generic env vars. npm does so, a lot – mostly to communicate the current npm config with processes – but it’s a completely different piece of software, it just happens to be shipped together with node.

And, btw, aren't some env variables set directly by node and npm?

I mean, you an always include process.env.PWD = process.cwd(); in your code? That’s the most reliable thing to do anyway.

@addaleax addaleax reopened this Apr 24, 2019
@Raiondesu
Copy link
Author

@addaleax, thank you very much for moving this!

PWD and cwd sometimes seem to be different (as stated here): PWD consistently points to a folder with node_modules (project directory), whereas cwd() points to directory from which the command was executed. Even though, these things often mean the same, sometimes they're not equal.
For example, if you run some npm script not from the project's root, but from an src directory:

project/ <-- project root (PWD)
  - dist/
  - src/ <-- we run command from here (cwd)

in bash:

user@pc: /home/user/project/src$ npm run script-that-logs-cwd-and-pwd
cwd: /home/user/project/src
PWD: /home/user/project
user@pc: /home/user/project/src$ _

or

user@pc: /home/user/project/src$ node
> process.cwd()
/home/user/project/src
> process.env.PWD
/home/user/project

In Windows PowerShell, however, this behaviour is broken:

PS ...\project\src> npm run script-that-logs-cwd-and-pwd
cwd: ...\project\src
PWD: undefined

or

PS ...\project\src> node
> process.cwd()
...\project\src
> process.env.PWD
undefined

hence, there is no reliable way to determine the project root directory by running the script.

It is not obvious, if PWD is related to node or to OS, since there's practically no documentation for it anywhere.

@addaleax
Copy link
Member

@Raiondesu As the linked stackoverflow question states, the reason that the two are different is that not every code that changes the current working directory also updates the PWD environment variable.

hence, there is no reliable way to determine the project root directory by running the script.

You could look up process.cwd() when the process is first started. The two values are typically only different when a part of the program explicitly calls process.chdir().

It is not obvious, if PWD is related to node or to OS, since there's practically no documentation for it anywhere.

It’s a bash feature: https://manpage.me/?q=bash (you can search for PWD).

@Raiondesu
Copy link
Author

Ok, I guess, I clearly misunderstood this part.

Thank you very much for making it clear for me and everyone else who sees this. 😊

lea-estia added a commit to dhmmasson/tamarin that referenced this issue Oct 2, 2020
replace process.env.PWD by process.cwd() in two files, until the project start.
Might cause problems as cwd might be different from PWD
nodejs/help#1881
dhmmasson added a commit to dhmmasson/tamarin that referenced this issue Feb 8, 2023
[FEATURE] track changes in blur or weight values
[FEATURE] local data structure and value for tamarin
[Data] Add washing machine dataset
[FEATURE] Offline computation - KendallTau Tests

[UPDATE] package-lock on windows by npm

[Fix] Remove sassMiddleware, update pkg
[FIX] fixing duplication of handles on update
[FIX] Get criteria to take into account the sorting order in the group clause (#29)
[FIX] PWD in windows

Offline computation of the impact of the granularity and importance factor using kendall tau test.
Test Granularity, Importance, Shape

replace process.env.PWD by process.cwd() in two files, until the project start.
Might cause problems as cwd might be different from PWD
nodejs/help#1881
fix the file criteria_get_all.sql, i added the column to the group clause, it should always be the same value.
When the criterion is updated from an event ( for ex. when onLoadState ) check if an handle exist before creating a new one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@bnoordhuis @addaleax @Raiondesu and others