Skip to content

fix(cloudflare): accept trailing commas in the wrangler config - #5142

Open
onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:fix/cloudflare-wrangler-jsonc-trailing-comma
Open

onmax wants to merge 1 commit into
nitrojs:mainfrom
onmax:fix/cloudflare-wrangler-jsonc-trailing-comma

Conversation

@onmax

@onmax onmax commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #5141

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

A trailing comma in the project's wrangler.jsonc or wrangler.json fails nitro build with SyntaxError: Expected double-quoted property name in JSON. Since confbox 0.3, parseJSONC only accepts trailing commas with allowTrailingComma: true. Wrangler accepts them in both files.

This PR passes allowTrailingComma: true when Nitro reads the Wrangler config. The new test in test/unit/cloudflare.utils.test.ts fails on main and passes here.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@onmax
onmax requested a review from pi0 as a code owner November 16, 2026 19:24
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@onmax is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

JSON and JSONC Wrangler configurations now allow trailing commas during parsing. A test verifies that writeWranglerConfig reads a commented wrangler.jsonc file with a trailing comma and includes its parsed values in the generated configuration.

Changes: Cloudflare configuration parsing

Layer / File(s) Summary
Allow trailing commas in Wrangler configuration
src/presets/cloudflare/utils.ts, test/unit/cloudflare.utils.test.ts
JSON and JSONC parsing now explicitly allows trailing commas. A test checks that writeWranglerConfig preserves the name and vars values from a commented wrangler.jsonc file.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug, preset:cloudflare

Merge Risk: Minimal · up to ad8c5

Nitro's Cloudflare build now accepts trailing commas in wrangler.json and wrangler.jsonc, matching Wrangler's behavior. Previously valid configs parse the same way, so the risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the conventional commits format (fix(cloudflare): ...) and describes the change: the Cloudflare preset now accepts trailing commas in the Wrangler config. This matches the main change, …
Description check Passed The description states the bug (a trailing comma in wrangler.jsonc or wrangler.json fails nitro build), the cause (confbox parseJSONC needs allowTrailingComma: true), the fix (passing that option when…
Linked Issues check Passed Issue #5141 requires Nitro's Cloudflare config reader to accept trailing commas in project wrangler.jsonc and wrangler.json files. At head, src/presets/cloudflare/utils.ts defines parseWranglerJSON as…
Out of Scope Changes check Passed The whole-PR diff against the merge base 749b12b changes only src/presets/cloudflare/utils.ts and test/unit/cloudflare.utils.test.ts. The source change swaps the JSON and JSONC parsers for a trailing-…
Full details: Title check

Explanation

The title uses the conventional commits format (fix(cloudflare): ...) and describes the change: the Cloudflare preset now accepts trailing commas in the Wrangler config. This matches the main change, which passes allowTrailingComma: true when Nitro reads wrangler.json and wrangler.jsonc.

Full details: Description check

Explanation

The description states the bug (a trailing comma in wrangler.jsonc or wrangler.json fails nitro build), the cause (confbox parseJSONC needs allowTrailingComma: true), the fix (passing that option when Nitro reads the Wrangler config), and the new test. This matches the changeset.

Full details: Linked Issues check

Explanation

Issue #5141 requires Nitro's Cloudflare config reader to accept trailing commas in project wrangler.jsonc and wrangler.json files. At head, src/presets/cloudflare/utils.ts defines parseWranglerJSON as parseJSONC(text, { allowTrailingComma: true }) and maps both the ".json" and ".jsonc" extensions to it. The TOML parser is unchanged. The new test in test/unit/cloudflare.utils.test.ts writes a wrangler.jsonc with a comment and trailing commas, runs writeWranglerConfig, and asserts that name and vars are parsed. The diff does not add a test for a wrangler.json file, but the code path for both extensions is the same. The issue does not require a specific test. The coding requirement is met.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base 749b12b changes only src/presets/cloudflare/utils.ts and test/unit/cloudflare.utils.test.ts. The source change swaps the JSON and JSONC parsers for a trailing-comma-tolerant parser. The test change adds one case for that behavior. Both changes connect directly to issue #5141. No unrelated changes were found in the diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb1a90df-5a3b-407d-8662-24c7d14c27f3
Commits

Reviewing files that changed from the base of the PR and between 749b12b and ad8c572.

Files selected for processing: 2

  • src/presets/cloudflare/utils.ts
  • test/unit/cloudflare.utils.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@5142

commit: ad8c572

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare: a trailing comma in wrangler.jsonc fails the build

1 participant