fix(mcp): load the import entry of an engine with separate import and require exports

BA
2d ago
+164-15

What and why

  • resolveEntry in packages/e2e/src/mcp/default-engine.ts found the entry with createRequire().resolve(), so it used the require conditions. It only read the import entry when that threw ERR_PACKAGE_PATH_NOT_EXPORTED. The entry is then loaded with import(), so a package that exports both picked the require file.
  • Now it reads the import target from exports first (the existing importEntry helper: import, node, or default, in the order written). require resolution stays for packages whose exports give no import target, or that have no exports.
  • An import target that is missing on disk is reported as "installed ... but its entry cannot be resolved", like the other unloadable entries, instead of falling back to the require file.
  • Patch changeset for e2e. No docs change: the docs do not describe how the entry is picked.

Issue

Fixes #1758

Verified

Ran it locally: yes

  • New unit test in mcp-default-engine.test.ts: a package with { import: './index.js', require: './index.cjs' } on . and on a subpath (written require first), each file returning an engine with a different name.
mainthis branch
from-require (test fails)from-import for dual and dual/web
  • vitest run tests/unit: 3654 pass, 1 skipped.
  • pnpm check green.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.