Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Version
v25.2.0
Platform
$ uname -a
Darwin furnace 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:26 PDT 2025; root:xnu-11417.121.6~2/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
mkdir -p folder-1/nested/ folder-2/
echo 'console.log("Hello, world!")' > folder-2/code.js
ln -s folder-1/nested/ ./symlink-dirFile tree looks like this:
./
├── folder-1/
│ └── nested/
├── folder-2/
│ └── code.js
└── symlink-dir -> folder-1/nested/
This command fails since node resolves the path incorrectly.
node ./symlink-dir/../../folder-2/code.js
How often does it reproduce? Is there a required condition?
Above instructions always reproduces the issue.
What is the expected behavior? Why is that the expected behavior?
I expect node to run the code.js script and print "Hello, world!".
I tried other tools to see how they handle it, and other than Deno nothing else I tried had trouble.
eg:
❯❯❯ cat ./symlink-dir/../../folder-2/code.js
console.log("Hello, world!")
❯❯❯ realpath ./symlink-dir/../../folder-2/code.js
/Users/athir/projects/.tmp/node-symlink-bug/folder-2/code.js
❯❯❯ bun ./symlink-dir/../../folder-2/code.js
Hello, world!
❯❯❯ deno ./symlink-dir/../../folder-2/code.js # deno has same issue
error: Module not found "file:///Users/athir/projects/.tmp/folder-2/code.js".What do you see instead?
node:internal/modules/cjs/loader:1423
throw err;
^
Error: Cannot find module '/Users/athir/projects/.tmp/folder-2/code.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1420:15)
at defaultResolveImpl (node:internal/modules/cjs/loader:1058:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1063:22)
at Module._load (node:internal/modules/cjs/loader:1226:37)
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
at node:internal/main/run_main_module:33:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v25.2.0
Path node sees: /Users/athir/projects/.tmp/folder-2/code.js
Actual path: /Users/athir/projects/.tmp/node-symlink-bug/folder-2/code.js
Additional information
I encountered this while using pnpm which generates bin shims which suffer from this issue. I intend to create an issue there as well.
Metadata
Metadata
Assignees
Labels
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
Activity
[-]Paths with directory symlinks are resolved incorrectly when passed to the node bin[/-][+]Node incorrectly resolves relative paths with directory symlinks[/+]richardlau commentedon Nov 14, 2025
You need to use
--preserve-symlinks--preserve-symlinks-mainnoc7c9 commentedon Nov 14, 2025
Thanks for letting me know about those flags but they didn't fix the issue.
Unless I'm misunderstanding something, I would've been surprised if those flags did fix it too given that the problem seems to be that Node is preserving the symlink path when it shouldn't be.
siaeyy commentedon Nov 18, 2025
In your case, looks like symlinks in entry point are not respected:
node/lib/internal/process/pre_execution.js
Lines 273 to 286 in 037a673
This doesnt depend on the filesystem, so I think instead of just using
path.resolve, we should usefs.realpathSynctoo.(
path.resolvefor when preserving symlinks)But seems like there is also one problem with
fs.realpathSync:It handles relative parts first and then expands symlinks, rather than doing these in reverse order.
I dont know if this is its normal behaviour but I assume it should be same as the native one (realpath(3))
I am going to open another issue.
github-actions commentedon Jun 17, 2026
This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
github-actions commentedon Jul 18, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.