fix(e2e): load a directory's index.ts through a package subpath or # import

Merged
KA
13d ago
+56-26
  • Node.js throws ERR_UNSUPPORTED_DIR_IMPORT when an ES module import names a directory. e2e's loader moved only ERR_MODULE_NOT_FOUND onto the TypeScript file behind the target (packages/e2e/src/config/esm-hooks.ts, resolveExport), so these failed collection from a .ts test or helper:
    • a subpath of a workspace package without exports that is a directory: @calcom/prisma/enums → packages/prisma/enums/index.ts
    • an exports entry that names a directory
    • a # import mapped to a directory
  • Both codes now take the same fallback, so the directory loads its main or index.ts, the way TypeScript resolves it and the way a relative ./dir import already did.
  • The unit test's stand-in resolver reported a directory as ERR_MODULE_NOT_FOUND (it read the path and got EISDIR), so the existing #dir case passed while the real import failed. It now throws what Node.js throws. The integration fixture gains a package without exports imported as @scope/legacy/enums and as #legacy/enums.
  • Not covered: under Yarn PnP, a package subpath that names a directory still fails. PnP's resolver throws ERR_MODULE_NOT_FOUND without the target's url, so the loader can't tell which directory it found. The # case already worked under PnP. The docs and the changeset say so.
  • Found while migrating cal.com's Playwright suite with the migrate-to-e2e skill (#1109): its Prisma factory imports @calcom/prisma/enums.
// tests/enums.e2e.ts in a monorepo whose workspace package has no `exports`
import { MembershipRole } from '@calcom/prisma/enums';

Verified

Ran it locally: yes

  • calcom/cal.com@54343aa, a test importing @calcom/prisma/enums, run with npx e2e run. I swapped this branch's built dist/config/esm-hooks.js into its node_modules/e2e:
e2e 0.20.0 (main)this branch
COLLECTION_ERROR: Directory import '…/node_modules/@calcom/prisma/enums' is not supported resolving ES modules imported from …/tests/enums-probe.e2e.ts✓ tests/enums-probe.e2e.ts (1 test), 1 passed
  • tests/integration/typescript-loader.test.ts with the fix reverted fails with the same Directory import … @scope/legacy/enums collection error; with it, 12/12 pass. The unit file's #dir case also fails with the fix reverted.
  • A fresh-context review checked that ERR_UNSUPPORTED_DIR_IMPORT carries url on Node 22.22.3, 22.23.2, 24.8.0, 24.21.0, and 26. It also checked that require() of a directory still fails as Node reports it, and that a JavaScript importer still gets Node's resolution. It found the Yarn PnP gap above and a stale header comment; both are addressed.