fix(templates): guard realpath crash in with-cloudflare-d1 on Cloudflare Workers#17392
Open
SybyAbraham wants to merge 1 commit into
Open
fix(templates): guard realpath crash in with-cloudflare-d1 on Cloudflare Workers#17392SybyAbraham wants to merge 1 commit into
SybyAbraham wants to merge 1 commit into
Conversation
This was referenced Jul 17, 2026
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.
Problem
The
with-cloudflare-d1template crashes with a 500 on every request when deployed to Cloudflare Workers:The
realpath()helper returnsundefinedwhenfs.existsSync()is false — which is the case for everyprocess.argventry in the Workers runtime (no filesystem). The subsequent.endsWith()call onundefinedthrows.This was introduced in #15098, which replaced a simple regex check with
realpath().endsWith()to also supportpayload run. The change works in Node.js but doesn't account for the Workers edge environment.Fix
Two guards:
realpath()—fs.existsSync()andfs.realpathSync()may throw in runtimes without a filesystem..endsWith()— ifrealpath()returnsundefined, returnfalseinstead of calling a method onundefined.No behavioral change in Node.js —
realpath()still returns the same values for existing file paths, andundefinedfor non-existent ones (which now safely returnsfalseinstead of throwing).Verification
Deployed to Cloudflare Workers and confirmed:
payload generate:types,payload migrate:create)