Repository navigation
Description
TL;DR
pnpm payload generate:types fails on the file layout that create-payload-app itself scaffolds (collections in separate files imported extensionless from payload.config.ts). Root cause is in tsx/esm/api's tsImport() — its scoped registration doesn't propagate to nested extensionless imports the way tsx's CLI-style global registration does. bin.js uses tsImport() (line 27–29), so the bug surfaces here.
Versions
[email protected],@payloadcms/[email protected],@payloadcms/[email protected][email protected](transitive via Payload)- Next.js 16.2.6, Node v22.22.2, pnpm 11.1.0, Linux (WSL2)
Minimal repro
- Existing Next.js 16 app, no top-level
app/layout.tsx(moved into a route group to satisfy Payload v3's requirement). pnpm dlx create-payload-app@latest --db postgres --db-connection-string "\$DATABASE_URL" --no-agent— scaffoldssrc/payload.config.ts+src/collections/{Users,Media}.ts. Imports look likeimport { Users } from './collections/Users'(extensionless, as the CLI writes them).- Add a third collection (
Pages) in a separate file with the same pattern, import it the same way. - Fix the well-known CLI bugs (esbuild placeholder in
pnpm-workspace.yaml, missingsharpdep, missing@payload-configtsconfig alias, mongoose-vs-postgres adapter mismatch when internalpnpm addfails on ignored builds — happy to file separately). pnpm typecheckclean,pnpm devworks,/adminserves correctly, schema pushes to Postgres.- Run
pnpm payload generate:typesto regenerate types for the newPagescollection.
Expected
src/payload-types.ts regenerates with the Page interface.
Actual
```
Error [ERR_MODULE_NOT_FOUND]: Cannot find module
'/path/to/project/src/collections/Users'
imported from /path/to/project/src/payload.config.ts
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
at moduleResolve (node:internal/modules/esm/resolve:861:10)
at defaultResolve (node:internal/modules/esm/resolve:985:11)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at resolve (file:///path/to/project/node_modules/.pnpm/[email protected]/.../dist/esm/index.mjs:2:5279)
at nextResolve (node:internal/modules/esm/hooks:748:28)
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///path/to/project/src/collections/Users'
```
tsx's resolve hook IS in the chain, but defers to nextResolve (Node default) without trying .ts/.tsx extensions.
Investigation
The same extensionless import resolves correctly under tsx's CLI-style global registration:
```bash
node --import='tsx/esm' --env-file=.env.local -e \
"import('./src/payload.config.ts').then(c => console.log(typeof c.default))"
```
→ loads payload.config.ts, resolves ./collections/Users, fails downstream on something unrelated (loadEnvConfig from Next.js's env loader — distinct from this issue).
So tsx itself handles extensionless nested imports — but only under global registration. The tsImport() programmatic API used by bin.js:27-29 doesn't propagate resolution to nested imports the same way.
Five other workaround paths tried, each failed differently (architectural-problem signature — stopped at 5 attempts):
--use-swc+@swc-node/[email protected]→SyntaxError: ./collections/Media does not provide an export named 'Media'- Custom wrapper importing
payload/dist/bin/generateTypes.js→ERR_PACKAGE_PATH_NOT_EXPORTED(internal not in exports map) node --import='tsx/esm' node_modules/payload/dist/bin/index.js→ silent (only exportsbin, never calls it)node --import='tsx/esm' --env-file=.env.local payload/bin.js generate:types --disable-transpile→ERR_REQUIRE_CYCLE_MODULEonpayload.config.ts(CJS↔ESM cycle from project's mixed module system)- Manually adding
.jsextensions to the imports (canonical Payload v3 ESM pattern) → fixes the CLI but breaks `pnpm dev` withERR_MODULE_NOT_FOUND(Next.js bundler can't findUsers.jssince onlyUsers.tsexists)
Suggested fix
In bin.js, switch from tsx/esm/api's tsImport() to Node's module.register('tsx/esm', ...) style global registration before invoking dist/bin/index.js. The CLI/global form is verified to handle nested extensionless imports; only the scoped programmatic form has the gap. Alternative: file upstream at privatenumber/tsx to make tsImport() behaviorally match the CLI for nested resolution.
Workaround in our project
Local typed cast in the consuming Server Component instead of importing the generated Page type — ~16 lines, 2-line semantic loss (no autocomplete on the Pages collection beyond what we declared in the local type).
Happy to provide a more reduced repro repo if useful.
Activity
SakshixSingh commentedon Jun 23, 2026
Hi team — this is ready for review when you have a moment.
This PR fixes
generate:typesfailing on extensionless collection imports (the defaultcreate-payload-applayout). Relevant unit test is included and passes locally.Thanks!
mhornbacher commentedon Sep 22, 2026
What is holding this fix up?
extension-less imports are quite standard and this is a real blocker for payload adoption?