content: Content API giving 404 on generate build
Environment
- Operating System:
Darwin - Node Version:
v16.18.0 - Nuxt Version:
3.4.3 - Nitro Version:
2.4.0 - Package Manager:
yarn@1.22.19 - Builder:
vite - User Config:
modules - Runtime Modules:
@nuxt/content@2.6.0 - Build Modules:
-
Reproduction
https://github.com/Tragio/nuxt-content-repro
yarn generate && yarn preview first selects works, and subsequent selects return 404.
yarn dev / yarn build works just fine.
Describe the bug
Nuxt Content with filter works just fine on dev, but as soon I generate the build it stops working properly.
Already tried all solutions provided here: https://github.com/nuxt/content/issues/1798
Additional context
No response
Logs
No response
CC: @farnabaz
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 3
- Comments: 27 (6 by maintainers)
I’m having similar issues where something like:
showed up when running
pnpm generate. And disabling SSR along with enabling clientDB solves the problem. But this also break the nuxt-image module and I’m not seeing any images or pictures. Any update or ideas on this problem?For someone interested, we fixed this issue in this way:
I hope this helps, however I don’t think it solves the initial reported problem …
I’m sure the nuxt team is already working on a definitive solution
@Tragio it’s working for me using these settings (note the casing on
clientDB)This is pretty much my day-to-day experience with Nuxt. Something always seems to break.
It’s really quite depressing when you’ve put so much work in to craft a website.
But for what i understand we both don’t want to use hybrid mode but just full static. But that doesn’t pre-render component logic?
I somehow get this problem solved, but with different ways in different versions of Nuxt.
In the latest Nuxt 3.7.3, the 404 error should point to a specific file that is missing from your content. Say, for me I have a
content/blogdirectory for holding all the blog posts, and set up apages/blog/[slug].vuefor rendering the blog page and apages/blog/index.vueto query content in that folder and render a index page. This should work fine in the Nuxt 3.7.3, but for some reason, in earlier versions of Nuxt, you might need want to try one of the two workarounds:content/blog/index.mdas a placeholder and manage to filter that out inpages/blog/index.vuepages/blog/index.vuetopages/blog.vueand also add a placeholdercontent/blog.md. You only need to make sure that the query path in yourpages/blog.vueis set to/blog/instead of/blog. (Note that this breaks at least in Nuxt 3.7.3 as it will make the child pages not accessible, but works in some earlier verions)I am facing the same issue with a search page that accepts user input via a text field to perform a search on the contents. The experimental clientDB fixes the issue, but degrades SEO as SSR has to be fully disabled.
It would be great to be able to force using the clientDB per query while still using SSR. I’ll try to get this done for the project I’m working on.
Have you tried this? https://image.nuxt.com/advanced/static-images
FWIW on Netlify what worked for me was:
ssrtotruenpm run build(vsgenerate)NITRO_PREFIX=netlify-edgeenvironment variableAnd FWIW Lighthouse performance shot up from mid 60s to 96 (98 on mobile!):
Site link here.
If you are facing issues with generating a static HTML file and receiving a 404 error, you need to add one of your routes to the static generation in nuxt.config.ts. After doing this, all files will be generated correctly.
Ahh it was a copy-paste issue 😋 for me it is also working. @farnabaz I was about to create a PR, but not sure if
nitro.preset: 'service-worker'does anything for the static deployment. If it should be replaced for what is there or added 🤔 maybe would be better for you to update the docs 🙏by:
Having the same problem as @Tragio this experimental clientdb setting doesn’t fix my problem still getting an 404.