Skip to content

fix: resolve extensionless imports in generate:types#17092

Open
SakshixSingh wants to merge 1 commit into
payloadcms:mainfrom
SakshixSingh:fix/generate-types-extensionless-imports
Open

fix: resolve extensionless imports in generate:types#17092
SakshixSingh wants to merge 1 commit into
payloadcms:mainfrom
SakshixSingh:fix/generate-types-extensionless-imports

Conversation

@SakshixSingh

Copy link
Copy Markdown
Contributor

Fixes #16734

Which branch should this PR target?

main — This is a bug fix in the v4 codebase. The same issue affects v3 users who run create-payload-app with extensionless collection imports.
What?
Fixes pnpm payload generate:types failing when payload.config.ts imports collections using extensionless paths (e.g. import { Users } from './collections/Users'), which is the layout create-payload-app scaffolds.

Before:

CLI fails with ERR_MODULE_NOT_FOUND for ./collections/Users.

After:

generate:types loads the config, resolves nested extensionless imports, and writes payload-types.ts successfully.

Why?

packages/payload/bin.js used tsx/esm/api's tsImport(), which only scopes TypeScript resolution to the entry file. Nested extensionless imports in the user's payload.config.ts are not resolved the same way as with node --import tsx/esm (global registration).

Users following the default scaffold could not regenerate types after adding new collections.

How?

Replaced scoped tsImport() with global tsx registration via register() from tsx/esm/api before dynamically importing the bin script.
Applied the same change in packages/graphql/bin.js and packages/plugin-mcp/bin.js for consistency.
Added packages/graphql/eslint.config.js so graphql/bin.js passes lint-staged (same pattern as packages/payload).
Added a unit test (packages/payload/src/bin/generateTypesExtensionlessImports.spec.ts) with a fixture at test/generate-types-extensionless/ that mirrors the scaffolded config layout.

Test plan

pnpm run build:payload

pnpm run test:unit -- packages/payload/src/bin/generateTypesExtensionlessImports.spec.ts

Manual: PAYLOAD_CONFIG_PATH=... node packages/payload/bin.js generate:types succeeds with extensionless imports

@SakshixSingh SakshixSingh changed the title fix : resolve extensionless imports in generate:types fix(payload): resolve extensionless imports in generate:types Jun 23, 2026
@SakshixSingh SakshixSingh changed the title fix(payload): resolve extensionless imports in generate:types fix: resolve extensionless imports in generate:types Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

payload generate:types fails with ERR_MODULE_NOT_FOUND on extensionless collection imports — tsx tsImport() scoped-registration gap

1 participant