fix: resolve extensionless imports in generate:types#17092
Open
SakshixSingh wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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