Skip to content

adapter-cloudflare: parse_redirects does not skip comment lines, breaking _routes.json #15324

@Murzav

Description

@Murzav

Describe the bug

@sveltejs/adapter-cloudflare@7.2.7 introduced _redirects parsing for _routes.json exclude rules (from #9138). However, the parse_redirects() function in utils.js does not skip comment lines (lines starting with #).

This causes comments like # Redirects for Cloudflare Pages to be parsed as redirect rules — the first word # gets added to the _routes.json exclude array. Cloudflare Pages then rejects the deployment with:

Error 8000057: Rules must start with '/' in `_routes.json`

Reproduction

  1. Create a _redirects file in project root with any comment:

    # This is a comment
    
  2. Build with adapter-cloudflare@7.2.7:

    SVELTE_ADAPTER=cloudflare npm run build
  3. Inspect .svelte-kit/cloudflare/_routes.json — it contains "#" in the exclude array:

    {
      "version": 1,
      "include": ["/*"],
      "exclude": [
        "/_app/version.json",
        "/_app/immutable/*",
        "/icons/icon-generator.html",
        "/manifest.json",
        "#"
      ]
    }
  4. Deploy to Cloudflare Pages — fails with error 8000057.

Workaround

Remove all comments from the _redirects file (or delete it if empty).

Severity

This is a deployment blocker — any project with comments in _redirects cannot deploy to Cloudflare Pages with adapter-cloudflare 7.2.7.

System Info

adapter-cloudflare: 7.2.7
@sveltejs/kit: 2.52.0
OS: macOS Darwin 25.3.0
Node: 22.x

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions