Skip to content

Misleading GetStaticPathsRequired when redirect origin is dynamic and destination is static #16482

@izzyramirez

Description

@izzyramirez

Astro Info

Astro                    v6.1.5
Node                     v22.14.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/sitemap
                         @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When astro.config.mjs defines a redirect from a dynamic origin to a fully static destination — e.g. '/project/[slug]': '/'astro build fails with:

[GetStaticPathsRequired] `getStaticPaths()` function is required for dynamic routes.
Make sure that you `export` a `getStaticPaths` function from your dynamic route.
  Location:
    src/pages/index.astro:0:0

The error is reported against src/pages/index.astro — a static page that has no business being a dynamic route at all. There is no indication that the actual cause is a redirect entry in astro.config.mjs. (When the same configuration is built with @astrojs/cloudflare, the error is reported against the dynamic page being legitimately defined elsewhere in the project — also misleading.)

This appears to be a gap left by #15423 / #12036. That fix added an InvalidRedirectDestination error for the case where a dynamic destination doesn't match any existing route. In this case, the destination / does match a route (the index page), so the new validation passes — but the build still ends up in validateDynamicRouteModule() and throws the misleading GetStaticPathsRequired.

The mismatch here is param count, not destination existence:

#12036 (fixed) This issue
Origin /categories/[category] /project/[slug]
Destination /categories/[category]/1 (no matching route) / (matches index)
New InvalidRedirectDestination fires? Yes No
Result on 6.1.5 Clear error Misleading GetStaticPathsRequired

When this is combined with @astrojs/cloudflare (#15860), the workerd-side error body is also swallowed by the prerenderer and surfaced as a generic 500: Internal Server Error, which compounds the debugging time significantly.

What's the expected result?

Either:

  1. Preferred — At config validation time, detect that the redirect's destination has fewer (or different) dynamic params than the origin and throw a clear, redirect-specific error pointing at the offending entry in the redirects config. This is a natural extension of the validation fix(routing): improve error for invalid dynamic redirect destinations #15423 added in createRedirectRoutes().

  2. At minimum — When GetStaticPathsRequired is thrown for a route that was reached via a redirect, include the offending redirect rule (e.g. /project/[slug]/) in the error message and hint, so users can identify it without having to bisect their config.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-gb9tx9bk?file=src%2Fpages%2F%5Bslug%5D.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions