Skip to content

Comments

Fix bt eval for ESM-only dependencies#34

Open
parkerhendo wants to merge 3 commits intomainfrom
parker/eval-not-esm-bug
Open

Fix bt eval for ESM-only dependencies#34
parkerhendo wants to merge 3 commits intomainfrom
parker/eval-not-esm-bug

Conversation

@parkerhendo
Copy link
Contributor

@parkerhendo parkerhendo commented Feb 21, 2026

Summary

  • When a TypeScript eval imports an ESM-only package ("type": "module" with only "import" exports), tsx v4 fails because it compiles .ts → CJS regardless of load method. The CJS require() can't match the "import" condition in package.json exports, producing ERR_PACKAGE_PATH_NOT_EXPORTED.
  • Adds automatic retry: when tsx fails with a known ESM interop error, retries the eval using vite-node with BT_EVAL_FORCE_ESM=1, which skips the require() path in the eval-runner and uses Vite's bundler-based module resolution instead.
  • Adds a test fixture (eval-ts-esm-only-dep) with a local ESM-only package to verify the fix.

Test plan

  • cargo test eval_fixtures passes with the new eval-ts-esm-only-dep fixture
  • Existing eval fixtures continue to pass (tsx path unchanged when no ESM error)
  • Manual: bt eval --runner tsx against a project with ESM-only deps retries and succeeds

@parkerhendo parkerhendo force-pushed the parker/eval-not-esm-bug branch from f991d90 to 44933b4 Compare February 21, 2026 00:44
@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Latest downloadable build artifacts for this PR commit ba6623b97f5f:

Available artifact names
  • ``cargo-dist-cache
  • ``artifacts-plan-dist-manifest
  • ``artifacts-build-local-aarch64-unknown-linux-gnu
  • ``artifacts-build-local-x86_64-unknown-linux-gnu
  • ``artifacts-build-local-aarch64-apple-darwin
  • ``artifacts-build-local-x86_64-pc-windows-msvc
  • ``artifacts-build-local-x86_64-apple-darwin
  • ``artifacts-build-global

@parkerhendo parkerhendo changed the title parker/eval not esm bug Fix bt eval for ESM-only dependencies Feb 23, 2026
@parkerhendo parkerhendo requested a review from ankrgyl February 23, 2026 21:46
@parkerhendo parkerhendo marked this pull request as ready for review February 23, 2026 21:47
const preferRequire =
file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".cjs");
!forceEsm &&
(file.endsWith(".ts") || file.endsWith(".tsx") || file.endsWith(".cjs"));
Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

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