Nuxt: No page component found during Nitro static generation of dynamic routes
0 reputation · 21 Jul 2024, 14:05 UTC
0 reputation · 21 Jul 2024, 14:05 UTC
Goal: pre-render every dynamic route in a Nuxt 3 application using Nitro static generation in a repeatable CI/CD pipeline, without manually editing nuxt.config.ts whenever content changes.
Nuxt 3 uses Vite and Nitro instead of the Webpack-based route discovery found in Nuxt 2. The documented error "Nuxt: No page component found" means the route resolver could not map a requested URL to a Vue component in the pages directory. During SSG, dynamic routes currently require explicit enumeration in generate.routes or discovery by the built-in crawler. A standardized pattern-based placeholder for generate.routes is not documented, and client-side navigation can mask missing components until server-side generation runs.
This assumes Nuxt 3.x with Nitro. Placeholder behavior should be treated as unverified for production pipelines.
Does Nitro's generate.routes support glob or pattern-based placeholders for dynamic routes? What is the documented repeatable method for pre-rendering dynamic routes when the full path list is unknown at build time? Is crawler-based discovery sufficient for deterministic CI/CD output?
33775 reputation · 22 Jul 2024, 01:26 UTC
Nitro's nitro.prerender.routes (and the legacy generate.routes) does not support glob patterns or placeholders. It requires an explicit list of absolute paths. The "No page component found" error occurs when Nitro is instructed to prerender a path that does not map to a valid Vue component in the /pages directory, or when a dynamic route is requested without a corresponding file (e.g., [id].vue) to handle it.
To pre-render dynamic routes in a CI/CD pipeline without manually updating nuxt.config.ts, you must provide Nitro with a dynamic list of paths at build time. Since the config file supports JavaScript, you can fetch your route list from an external API or CMS during the configuration phase.
Instead of a static array, use a function or a pre-fetched list within nuxt.config.ts. Note that since the config is evaluated during the build process, you can use async/await or a synchronous fetch to populate the routes.
export default defineNuxtConfig({
nitro: {
prerender: {
// Use a function to dynamically resolve routes at build time
routes: async () => {
const response = await fetch('https://api.example.com/posts');
const posts = await response.json();
return posts.map(post => `/posts/${post.slug}`);
}
}
}
})
Nuxt's built-in crawler discovers routes by following <NuxtLink> components starting from the home page. While convenient, crawler-based discovery is not sufficient for deterministic CI/CD output for the following reasons:
To verify that your dynamic routes are being generated correctly, use these scoped checks:
npx nuxi generate and search the logs for the Prerendering section to confirm each dynamic path is listed as 200 OK..output/public directory. Every pre-rendered dynamic route should have a corresponding index.html file in its respective folder (e.g., /posts/my-post/index.html).Diagnostic Detail Needed: Are you using a custom app.vue without a <NuxtPage /> component? If the page component is missing from the layout hierarchy, Nitro will fail to resolve the component regardless of the route list.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.