Skip to content

fix: use processModule as receiver when falling back in process polyfill (#541)#542

Open
guoyangzhen wants to merge 1 commit into
unjs:mainfrom
guoyangzhen:fix-process-proxy-receiver
Open

fix: use processModule as receiver when falling back in process polyfill (#541)#542
guoyangzhen wants to merge 1 commit into
unjs:mainfrom
guoyangzhen:fix-process-proxy-receiver

Conversation

@guoyangzhen

@guoyangzhen guoyangzhen commented Mar 23, 2026

Copy link
Copy Markdown

πŸ”— Linked issue

Closes #541

πŸ“ Description

The process polyfill uses a Proxy to layer unenv's polyfill over the original process object. When a property doesn't exist on the proxy target, it falls back to processModule (unenv's polyfill implementation):

return Reflect.get(processModule, prop, receiver);

The problem: receiver is the Proxy wrapping the original process, not processModule. When processModule has getters that rely on private fields (like #stdout in the std implementations), Reflect.get invokes the getter with this = receiver β€” which is the wrong object and lacks the private fields.

This causes:

Uncaught TypeError: Cannot read private member #t from an object whose class did not declare it.

Fix

Pass processModule as the receiver instead of receiver:

- return Reflect.get(processModule, prop, receiver);
+ return Reflect.get(processModule, prop, processModule);

This ensures getters/methods on processModule are invoked with this = processModule, which has the expected private fields.

Credit

Solution identified by the issue reporter @unjs/unenv#541.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the property access behavior in the process polyfill to ensure proper context binding when accessing properties.

@guoyangzhen guoyangzhen requested a review from pi0 as a code owner March 23, 2026 04:11
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e2705be-7311-4771-8508-3373b5d49dcf

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between f89b7cc and 9e228a9.

πŸ“’ Files selected for processing (1)
  • src/runtime/polyfill/process.ts

πŸ“ Walkthrough

Walkthrough

The process polyfill's proxy get trap fallback was updated to use processModule as the receiver in Reflect.get instead of the original proxy receiver, ensuring methods and getters in processModule maintain correct this context and access to private members.

Changes

Cohort / File(s) Summary
Process Polyfill Context Binding Fix
src/runtime/polyfill/process.ts
Changed Reflect.get third argument from receiver to processModule in proxy fallback to ensure private members and context-dependent properties are correctly bound when accessed through the proxy.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A proxy that bounced back the wrong frame,
Now processModule claims proper name,
With this context mended just right,
Private members shine in the light! ✨

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately describes the main change: fixing the process polyfill by using processModule as the receiver in the Reflect.get fallback.
Linked Issues check βœ… Passed The PR directly implements the proposed fix from issue #541: replacing Reflect.get(processModule, prop, receiver) with Reflect.get(processModule, prop, processModule) to resolve private field access errors.
Out of Scope Changes check βœ… Passed The change is minimal and focused: only the receiver argument in one Reflect.get call is modified, directly addressing the reported bug without introducing unrelated modifications.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

vernaillen added a commit to wpnuxt/wpnuxt that referenced this pull request Apr 29, 2026
Applies upstream PR unjs/unenv#542 locally via pnpm patch.
Resolves "Cannot read private member #n" error when deploying to
vercel-edge / cloudflare workers. Patch can be removed once unenv
releases the fix.

Also enables vercel-edge preset and inline sourcemaps for the
playground (sourcemaps to be removed after edge deploy verifies green).
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

Successfully merging this pull request may close these issues.

Potentially incorrect polyfill for globalThis.process

1 participant