Skip to content

fix: infinite loop in findConfig when tsconfig rootDir is relative - #18327

Open
bbkysf wants to merge 1 commit into
payloadcms:3.xfrom
bbkysf:fix/relative-rootdir-infinite-loop-3.x
Open

bbkysf wants to merge 1 commit into
payloadcms:3.xfrom
bbkysf:fix/relative-rootdir-infinite-loop-3.x

Conversation

@bbkysf

@bbkysf bbkysf commented Sep 25, 2026

Copy link
Copy Markdown

What?

payload CLI commands that locate the config (e.g. generate:types) hang forever at 100% CPU when tsconfig.json has a relative compilerOptions.rootDir (like "./") and no @payload-config path / PAYLOAD_CONFIG_PATH.

Why?

getTSConfigPaths() used rootDir / outDir as-is, unlike baseUrl and @payload-config, which are resolved against the tsconfig directory. findConfig() then calls findUpSync({ dir: './' }), and since path.parse('./').root === '' and path.dirname('.') === '.', dir never equals root, so the while (true) loop never exits.

Repro: https://github.com/bbkysf/payload-rootdir-hang

How?

  • config/find.ts: resolve rootDir and outDir relative to the tsconfig directory (matching TypeScript's semantics and how baseUrl is already handled).
  • utilities/findUp.ts: path.resolve(dir) at the start of findUpSync / findUp, so a relative dir from any caller always terminates at the filesystem root.
  • Added unit tests for both (find.spec.ts, findUp.spec.ts). Without the fix, these tests hang; with it they pass. All packages/payload unit tests pass.

The same change applies cleanly to main (the files are identical there).

Fixes #18324

getTSConfigPaths() used compilerOptions.rootDir/outDir as-is. With a
relative value like "./", findUpSync never reached the filesystem root
(path.dirname('.') === '.', path.parse('.').root === ''), so any CLI
command that calls findConfig (e.g. generate:types) hung at 100% CPU.

- resolve rootDir/outDir against the tsconfig directory, like baseUrl
- resolve dir in findUp/findUpSync so a relative dir always terminates

Fixes payloadcms#18324
@bbkysf

bbkysf commented Oct 31, 2026

Copy link
Copy Markdown
Author

Hi @denolfe, @AlessioGr 👋

This fixes #18324: payload generate:types (and other commands that call findConfig) hangs at 100% CPU when tsconfig.json has a relative rootDir like "./" or "." and no @payload-config path. rootDir/outDir are now resolved against the tsconfig directory, like baseUrl, and findUp/findUpSync resolve a relative dir so they always reach the filesystem root. This is a related gap to #12457.

I also confirmed the bug still exists on main (4.0.0-beta.6), see my comment on the issue. CI is green and both changes have unit tests. Could one of you take a look when you have a chance? I'll open the matching PR against main once this one is reviewed, so any feedback applies to both.

Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants