#404 on a path

4 messages · Page 1 of 1 (latest)

gray swallow
#

@dusky kraken so I have this in config

vite: {
        build: {
            rollupOptions: {
                external: ['/pagefind/pagefind.js']
            }
        },
        server: {
            fs: {
                strict: false,
                allow: ['.']  // Allow serving files from root
            }
        },
        optimizeDeps: {
            exclude: ['pagefind']
        }
    }

and I'm getting error

0:43:31 [WARN] [router] A `getStaticPaths()` route pattern was matched, but no matching static path was found for requested path `/pagefind/pagefind.js`.

Possible dynamic routes being matched: src/pages/[...slug].astro.
20:43:31 [404] /pagefind/pagefind.js 252ms
dusky krakenBOT
#

Hi @gray swallow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the error message you're seeing, it appears that Astro is trying to handle the /pagefind/pagefind.js route as a dynamic route, but it can't find a matching static path. This is likely because the file is not being recognized as a static asset.

The issue seems to be related to how Astro is handling the pagefind.js file. Here are a few potential solutions:

  1. Exclude the route from dynamic routing:
    You can try to exclude the /pagefind/ route from being processed by Astro's dynamic routing. According to the Astro documentation on Cloudflare integration (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#routesextend), you can use the routes.extend.exclude option to serve static assets directly:

    export default defineConfig({
      adapter: cloudflare({
        routes: {
          extend: {
            exclude: [{ pattern: '/pagefind/*' }],
          }
        },
      }),
    });
    

    This should prevent Astro from trying to handle /pagefind/pagefind.js as a dynamic route.

  2. Move the file to the public directory:
    If possible, consider moving the pagefind.js file to the public directory in your Astro project. Files in the public directory are served as-is and are not processed by Astro's routing system.

  3. Check your dynamic routes:
    The error message mentions a possible match with src/pages/[...slug].astro. Make sure this dynamic route is not inadvertently catching the /pagefind/pagefind.js path. You might need to adjust your dynamic route logic to exclude this path.

  4. Verify the file location:
    Ensure that the pagefind.js file is actually where you expect it to be in your project structure.

#

If these solutions don't resolve the issue, you may need to provide more information about your project structure and how you're using the pagefind.js file. The Astro documentation on routing (https://docs.astro.build/en/guides/routing/) might also be helpful for understanding how Astro handles different types of routes.

Remember, the error suggests that Astro is trying to handle this as a dynamic route, so the key is to either exclude it from dynamic routing or ensure it's served as a static asset.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: