fix(ext/node): tolerate unreadable cwd in require._nodeModulePaths#34542
Merged
Conversation
`op_require_node_module_paths` always called `env_current_dir()` for non-`file:///` paths, even when the incoming `from` was already absolute. On macOS, `getcwd()` walks the directory tree from `/` and fails with EACCES if any ancestor is unreadable (e.g. running under `su nonadmin` from a directory the unprivileged user can't read — see deno#21585), which crashed `createRequire(import.meta.url)` for any spawned `deno -e` child even though the absolute path didn't need the cwd at all. Skip the cwd lookup when `from` is already absolute, and enable the previously-disabled node compat tests `test-cwd-enoent.js` and `test-cwd-enoent-preload.js` which exercise this path. Closes denoland/orchid#284 Co-Authored-By: Divy Srivastava <[email protected]>
littledivy
approved these changes
May 30, 2026
littledivy
added a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
…enoland#34542) ## Summary `op_require_node_module_paths` always called `env_current_dir()` for non-`file:///` paths, even when the incoming `from` was already absolute. On macOS, `getcwd(3)` walks the directory tree from `/` and fails with `EACCES` if any ancestor is unreadable — e.g. running under `su nonadmin -c "..."` from a directory the unprivileged user can't read, the scenario from denoland#21585. That cwd lookup then bubbled up as `NotFound: Unable to get CWD`, crashing `createRequire(import.meta.url)` (which deno injects when `deno -e` is spawned as a child process via `child_process.spawn`) even though the absolute `import.meta.url` path didn't need cwd at all. Skip the cwd lookup when `from` is already absolute. The previous fix denoland#33587 made `Eval`/`Repl` fall back to a sentinel cwd at the workspace-factory layer, but the node-compat require ops sat below that and re-fetched cwd directly. ## Test plan Enables and passes two previously-skipped Node compat tests that spawn `deno -e 0` with the parent's cwd already unlinked (the same failure mode as the original macOS bug, just reachable on Linux): - `parallel/test-cwd-enoent.js` - `parallel/test-cwd-enoent-preload.js` `parallel/test-cwd-enoent-repl.js` (already enabled by denoland#33587) continues to pass. ``` $ cargo test --test node_compat test-cwd-enoent test node_compat::parallel::test-cwd-enoent-preload.js ... ok test node_compat::parallel::test-cwd-enoent-repl.js ... ok test node_compat::parallel::test-cwd-enoent.js ... ok ``` Closes denoland/orchid#284 Co-authored-by: divybot <[email protected]> Co-authored-by: Divy Srivastava <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
op_require_node_module_pathsalways calledenv_current_dir()for non-file:///paths, even when the incomingfromwas already absolute. On macOS,getcwd(3)walks the directory tree from/and fails withEACCESif any ancestor is unreadable — e.g. running undersu nonadmin -c "..."from a directory the unprivileged user can't read, the scenario from #21585. That cwd lookup then bubbled up asNotFound: Unable to get CWD, crashingcreateRequire(import.meta.url)(which deno injects whendeno -eis spawned as a child process viachild_process.spawn) even though the absoluteimport.meta.urlpath didn't need cwd at all.Skip the cwd lookup when
fromis already absolute. The previous fix #33587 madeEval/Replfall back to a sentinel cwd at the workspace-factory layer, but the node-compat require ops sat below that and re-fetched cwd directly.Test plan
Enables and passes two previously-skipped Node compat tests that spawn
deno -e 0with the parent's cwd already unlinked (the same failure mode as the original macOS bug, just reachable on Linux):parallel/test-cwd-enoent.jsparallel/test-cwd-enoent-preload.jsparallel/test-cwd-enoent-repl.js(already enabled by #33587) continues to pass.Closes denoland/orchid#284