Skip to content

Comments

fix bt eval with monorepo and without extensions in imports#15

Open
ibolmo wants to merge 6 commits intomainfrom
fix-bt-eval-monorepo
Open

fix bt eval with monorepo and without extensions in imports#15
ibolmo wants to merge 6 commits intomainfrom
fix-bt-eval-monorepo

Conversation

@ibolmo
Copy link

@ibolmo ibolmo commented Feb 12, 2026

Fix 1: TypeScript extension resolution in installNodeModuleHooks (lines 399-472)

The resolve hook now wraps the next() call in a try/catch. When resolution fails for an extensionless relative specifier (like ./processors/tool-call-processor), it retries with .ts, .tsx, .mts, .cts extensions appended. This makes module.registerHooks() (Node 22.14+/23.5+) handle extensionless TS imports natively, so both require() and import() work without tsx hooks.

Fix 2: ESM-package-aware loading order in loadFiles (lines 821-920)

The old code always tried require() first for .ts files. On Node < 22.14, calling require() on a file in a "type": "module" package triggers require-of-ESM, which can corrupt the module graph and cause the "Unexpected status" internal assertion error (nodejs/node#54577).
The new code adds isInsideEsmPackage() to check the nearest package.json. For TS files in "type": "module" packages, it now tries import() first. This avoids the CJS/ESM interop bug on older Node versions while preserving the original require()-first behavior for CJS packages (where tsx's hooks work best).

Fix 3: if customers use parseArgs with strict will throw an exception because we passed files in the args

@ibolmo ibolmo self-assigned this Feb 12, 2026
@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Latest install commands for this PR (updated for commit 1d7c52f75723):

  • Unix: curl -fsSL https://github.com/braintrustdata/bt/releases/download/canary-fix-bt-eval-monorepo/bt-installer.sh | sh
  • Windows: powershell -ExecutionPolicy Bypass -c "irm https://github.com/braintrustdata/bt/releases/download/canary-fix-bt-eval-monorepo/bt-installer.ps1 | iex"

Copy link
Contributor

@ankrgyl ankrgyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the repro address just #3 (arg parsing) or the fixes needed for #1 and #2 as well?

Comment on lines +206 to +208
// Fallback: read from argv for backwards compatibility (e.g., running
// the eval-runner directly outside of bt).
return process.argv.slice(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll split the PR. in the process of repro'ing #3 i found #1 and #2. this comment is part of the fix for #3.

https://github.com/braintrustdata/bt/pull/15/changes/BASE..1d7c52f75723f5035ce730754fa957114e3058f7#diff-ebfbecea6fc2203656d02c9898c507bee6517b02460e25c98d5b240a8ecdf57cR9

this is the line that repros the user's problem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customer will try again on monday so we have time to get this right

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.

2 participants