fix(e2e): load a directory's index.ts through a package subpath or # import
Merged
KA
13d ago+56+56+01234567890123456789-26-26-01234567890123456789
- Node.js throws
ERR_UNSUPPORTED_DIR_IMPORTwhen an ES moduleimportnames a directory. e2e's loader moved onlyERR_MODULE_NOT_FOUNDonto the TypeScript file behind the target (packages/e2e/src/config/esm-hooks.ts,resolveExport), so these failed collection from a.tstest or helper:- a subpath of a workspace package without
exportsthat is a directory:@calcom/prisma/enums→packages/prisma/enums/index.ts - an
exportsentry that names a directory - a
#import mapped to a directory
- a subpath of a workspace package without
- Both codes now take the same fallback, so the directory loads its
mainorindex.ts, the way TypeScript resolves it and the way a relative./dirimport already did. - The unit test's stand-in resolver reported a directory as
ERR_MODULE_NOT_FOUND(it read the path and gotEISDIR), so the existing#dircase passed while the real import failed. It now throws what Node.js throws. The integration fixture gains a package withoutexportsimported as@scope/legacy/enumsand as#legacy/enums. - Not covered: under Yarn PnP, a package subpath that names a directory still fails. PnP's resolver throws
ERR_MODULE_NOT_FOUNDwithout the target'surl, 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-e2eskill (#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 withnpx e2e run. I swapped this branch's builtdist/config/esm-hooks.jsinto itsnode_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.tswith the fix reverted fails with the sameDirectory import … @scope/legacy/enumscollection error; with it, 12/12 pass. The unit file's#dircase also fails with the fix reverted.- A fresh-context review checked that
ERR_UNSUPPORTED_DIR_IMPORTcarriesurlon Node 22.22.3, 22.23.2, 24.8.0, 24.21.0, and 26. It also checked thatrequire()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.