fix(node): use /bundle as cwd when evaluating dynamically imported modules #8797
<br/>Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.<br/>
- - -
I have read the CLA Document and I hereby sign the CLA
- - -
<sub>You can retrigger this bot by commenting recheck in this Pull Request. </sub><sub>Posted by the CLA Assistant Lite bot.</sub>
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
<!-- durable-reviewer:review -->
This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).
Approved these changes.
Hi @Jeremiah-D, thanks for the PR. Could you please sign the CLA so we can land it?
jasnell
Jeremiah-D
Fixes #8786.
With the new module registry, the top level of a dynamically imported module saw process.cwd() return
/instead of/bundle, and chdir() threw EPERM, so relative reads failed on//.... The eval callback in the new module registry suppresses the IoContext before evaluating, and nothing provided a TmpDirStoreScope, so getCurrentWorkingDirectory() had nothing to read. The legacy dynamic import path and the top-level bootstrap both declare a scope for exactly this reason, so this does the same in the callback — only when none is current yet, since the bootstrap already provides one while the main module is evaluated and the scope asserts against nesting. Temporary files created during evaluation are discarded with the scope, matching top-level behavior.Added a regression test: a lazily imported module asserts cwd is /bundle at its top level, chdirs to /tmp and back, and reads a sibling bundle module by relative path. I could not run the wd-test locally (no bazel in this environment), so that part relies on CI.