Skip to content

fix(node/events): guard async-generator reflection for targets below … - #568

Open
ayushdwivedi-stack wants to merge 1 commit into
unjs:mainfrom
ayushdwivedi-stack:fix/events-async-iterator-prototype
Open

ayushdwivedi-stack wants to merge 1 commit into
unjs:mainfrom
ayushdwivedi-stack:fix/events-async-iterator-prototype

Conversation

@ayushdwivedi-stack

@ayushdwivedi-stack ayushdwivedi-stack commented Oct 9, 2026 •

Copy link
Copy Markdown

Resolves #565

🔗 Issue

🐞 Reproduction

In an ES2015/ES2017 bundle (e.g. via esbuild, Babel, or tsc):

import { EventEmitter } from "unenv/node/events";
console.log("loaded:", typeof EventEmitter);


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Bug Fixes**
  * Improved compatibility when the runtime cannot provide the expected async-iterator prototype. Event functionality can now initialize using a fallback instead of failing during startup.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 07178804-4d26-4796-a2b1-acf60503f448

📥 Commits

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


📒 Files selected for processing (2)
  • src/runtime/node/internal/events/events.ts
  • test/events.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

The events module now guards async-iterator prototype lookup and falls back to Object.prototype when lookup fails or returns a falsy value. Tests cover event delivery, async-iterator behavior, and execution of an ES2015-targeted bundle.

Changes

Events compatibility

Layer / File(s) Summary
Guard async-iterator prototype lookup
src/runtime/node/internal/events/events.ts
AsyncIteratorPrototype falls back to Object.prototype if nested prototype lookup throws or returns a falsy value.
Validate event delivery and ES2015 bundle
test/events.test.ts
Tests check event delivery, async-iterator values and early termination, and execution of an ES2015-targeted bundle. The integration test removes its temporary directory in a finally block.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to ffe31

The compatibility regression is covered by the bundle test, and no merge-blocking issue remains.

🚥 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 clearly identifies the main change: guarding async-generator reflection in node/events for targets below ES2018. It is concise and directly related to the implementation and issue objective.
Linked Issues check Passed Issue [#565] requires node/events to load when async-generator prototype reflection is unavailable below ES2018. events.ts now performs the reflection inside try/catch and falls back to `Object.…
Out of Scope Changes check Passed The source change directly addresses the module-loading failure in [#565]. The added unit and ES2015 integration tests verify module loading and related event-iterator behavior. No unrelated change is…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…


✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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.

node/events: unguarded async-generator reflection breaks the module when bundled below ES2018

1 participant