-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Incorrect cwd() inside subfolders of Windows directory symlinks or junctions #34866
Comments
Deep, deep inside For babel, this probably can be worked around. Cwd is defined by the caller, so maybe adding fs.realpath.native call might help? Also, the cwd printed by Node depends on how you entered the folder. Basically, I cant reproduce. If I do C:\...\test>cd link
C:\...\test\link>node -p process.cwd()
C:\...\test\link
C:\...\test\link>cd ..\folder
C:\...\test\folder>node -p process.cwd()
C:\...\test\folder
C:\...\test\folder>cd ssub
C:\...\test\folder\sub>node -p process.cwd()
C:\...\test\folder\sub
C:\...\test\f\s>cd ..\..\link\sub
C:\...\test\link\sub>node -p process.cwd()
C:\...\test\link\sub
|
Yes, I think ultimately the bug is in win32 If I interpret your results correctly, they already show the bug as |
I don't think this is something we can fix. Forcing Running this script in the const path = require('path')
const fs = require('fs')
const cwd = path.join(fs.realpathSync(process.cwd()), 'sub');
require('child_process').spawnSync(
process.execPath,
['-p', 'process.cwd()'],
{ stdio: 'inherit',
cwd
}
); produces: C:\...\test\link>node t.js
C:\...\test\folder\sub |
It should probably be a semver-major change to be safe but I think it's the right thing to so it works the same on Unix (which already seems to return realpath in all cases) and Windows. |
For the record, subst would work if we would do a realpath on all child cwd: C:\...\test\>subst z: C:\...\test
C:\...\test\>z:
Z:\>cd link
Z:\link>node t.js
Z:\folder\sub Bringing Windows and Unix closer together is always a good thing, but I would expect something somewhere to break horribly. We should probably do both a realpath on CWD when starting and when doing /cc @nodejs/platform-windows |
Hi, just stumbled across this and I'm confused: In Linux shell: # setup
$> cd && pwd
/home/jahudka
$> mkdir folder
$> ln -s $(pwd)/folder link
# test
$> cd ~/folder && pwd
/home/jahudka/folder
$> node -e 'console.log(process.cwd());'
/home/jahudka/folder
$> cd ~/link1 && pwd
/home/jahudka/link
$> node -e 'console.log(process.cwd());'
/home/jahudka/folder As you can see, in Linux the symlink in # setup
$> cd && pwd
/home/jahudka
$> mkdir -p folder1/folder2/folder3
$> ln -s $(pwd)/folder1/folder2 link
# test
$> cd ~/link/folder3 && pwd
/home/jahudka/link/folder3
$> node -e 'console.log(process.cwd());'
/home/jahudka/folder1/folder2/folder3 So it seems NodeJS is already doing what you guys want it to do (ie. resolving symlinks in CWD always).. and there appears to be no way to convince it to do what I want (which is the exact opposite, ie. never resolve symlinks in CWD).. sux for me 😂 I've tested this on Node 12 and 14 on Debian and macOS and it behaves exactly the same everywhere. |
|
Still relevant found in LTS (v20.11.1) and latest (v21.6.2). |
I have locally implemented a draft to assess the impact of this fix. The tests ran on both libuv and Node and a significant number of tests failed. This inconsistency originates from the Windows API, which has evolved into a feature over time. Therefore, it appears infeasible to fix this issue without affecting a lot of users. With all this considered, I propose closing this issue. |
Since there have been no objections after the last comment, which was left a long time ago, I'll close this now. Please reopen if needed. |
What steps will reproduce the bug?
Same behaviour with
/J
(junction) instead of/D
(directory symlink).What is the expected behavior?
It should resolve the path to
C:\folder\sub
, similar to how it works for symlinks on Unix:Additional information
__filename
,__dirname
andfs.realpath(".")
correctly resolve,process.cwd()
andpath.resolve(".")
don't.Related issue: babel/babel#10232
The text was updated successfully, but these errors were encountered: