Skip to content

fix: Bun runtime compatibility for child process channel ref/unref - #1816

Open
skoshx wants to merge 1 commit into
mainfrom
cursor/triage-1815-3b9b
Open

skoshx wants to merge 1 commit into
mainfrom
cursor/triage-1815-3b9b

Conversation

@skoshx

@skoshx skoshx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause

The error "child.channel?.unref is not a function" occurs in /agent/repos/react-doctor/packages/core/src/utils/set-child-process-ref.ts. The code calls child.channel?.ref() and child.channel?.unref() assuming that if child.channel exists, it will have these methods (standard Node.js IPC channel API).

In Bun: The child.channel property exists but doesn't implement the ref()/unref() methods, causing the runtime error.

Solution

Make the calls defensive by checking if the methods exist before calling them:

if (typeof child.channel?.ref === "function") {
  child.channel.ref();
}
// and
if (typeof child.channel?.unref === "function") {
  child.channel.unref();
}

This makes the code compatible with both Node.js and Bun runtimes.

Changes

  • Modified packages/core/src/utils/set-child-process-ref.ts to check if methods exist before calling
  • Added comprehensive unit tests in packages/core/tests/set-child-process-ref.test.ts covering:
    • Normal Node.js behavior (when channel has ref/unref methods)
    • Bun behavior (when channel exists but doesn't have ref/unref methods)
    • When channel doesn't exist at all
  • Added changeset documenting the fix

Testing

  • All existing tests pass (2536 tests in core package)
  • New unit tests specifically cover the Bun runtime scenario
  • Lint and typecheck pass

Closes #1815

Open in Web Open in Cursor 

Check if channel methods exist before calling them to fix runtime error:
"child.channel?.unref is not a function" when running under Bun.

Closes #1815

Co-authored-by: Skosh <skoshx@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-react-doctor@1816
npm i https://pkg.pr.new/oxlint-plugin-react-doctor@1816
npm i https://pkg.pr.new/react-doctor@1816

commit: 038915f

@github-actions

Copy link
Copy Markdown
Contributor

Interactive terminal E2E

Terminal Control verified the built CLI at 038915f in a real PTY:

  • selected a project interactively and observed Scanning... before the three-second Git delay completed
  • waited for the clean result and exercised the compact report
  • opened copy context and the GitHub Actions confirmation, then cancelled safely

Download the edited MP4 and PNG evidence

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.

CLI error: child.channel?.unref is not a function. (In 'child.channel?.unref()', 'child.channel?.unref' is undefined)

2 participants