content: Production Build: queryContent Triggers 500 Internal Server Error
Environment
- Operating System: Darwin
- Node Version: v21.2.0
- Nuxt Version: 3.10.3
- CLI Version: 3.10.1
- Nitro Version: 2.9.1
- Package Manager: pnpm@8.9.2
- Builder: -
- User Config: devtools, modules, content
- Runtime Modules: @nuxt/content@2.12.0
- Build Modules: -
Reproduction
Repo: https://github.com/santiagoaloi/nuxt_content_issue Live: https://nuxt-content-issue.vercel.app/
Describe the bug
Iβm encountering a production-specific 500 error when using queryContent in any Vue SFC component within my Nuxt 3 project. This issue does not occur during development.
Steps to Reproduce:
1- Create a fresh Nuxt 3 project (no custom configurations or additional libraries).
2- Define some content using the @nuxt/content module., e.g a file named hello.json with the following content:
{
"title": "Hello Content v2!",
"description": "The writing experience for Nuxt 3",
"category": "announcement"
}
3- In any SFC component, attempt to fetch content using queryContent:
<template>
<main>
{{ data }}
</main>
</template>
<script setup lang="ts">
import { queryContent } from '@nuxt/content'
const data = await queryContent('/hello').findOne()
</script>
4- Build the project for production:
pnpm build && pnpm preview
5- Run the production server and the app in the browser.
Expected Behavior:
The content defined in page should be successfully retrieved and displayed in the componentβs template.
Actual Behavior:
The server throws a 500 Internal Server Error. The error log typically includes:
[GET] "/api/query/yFRQI29ykM.1709594450379.json?_params=%7B%22first%22:true,%22where%22:%5B%7B%22_path%22:%22%2Fhello%22%7D%5D,%22sort%22:%5B%7B%22_file%22:1,%22$numeric%22:true%7D%5D%7D": 500
Additional context
Iβve also attempted the following troubleshooting steps:
Deployment to Vercel: I deployed the project to Vercel to see if the issue was specific to my local development environment. However, the 500 error persisted in the production build on Vercel.
Nitro Prerender Settings: I experimented with various Nitro prerender settings in an attempt to resolve the issue, but none of the configurations seemed to address the problem.
Nitropack Override: I tried overriding the default Nitropack version in the package.json file by adding the following configuration:
"overrides": {
"nitropack": "2.8.1"
}
However, this attempt also did not resolve the 500 error.
Logs
No response
### Tasks
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Reactions: 6
- Comments: 15 (1 by maintainers)
Commits related to this issue
- chore: downgrade Nitro Fixes https://github.com/nuxt/content/issues/2580 — committed to kirby-tools/kirbyseo.com by johannschopplich 4 months ago
This issue is resolved in the latest Nitro version (v2.9.3).
For reference: https://github.com/unjs/nitro/pull/2239.
We can all remove the resolutions override and use the latest Nitro version again. π
Hi,
Not sure if it helps but just leaving some feedback here. I also came across this issue (or very similar, error 500 when querying content only on prod) and managed to fix it by adding the following in my package.json:
Using yarn v4 with nodeLinker: node-modules
Additionally
running this in production, while owning a /content/articles folder with .md files in it, returns an empty Array.
Using
resolutionsandnitropack@2.8.1indeed resolves the issue. I appreciate you sharing this workaround. πFor this one I had raised an issue in the
@nuxthub/corerepo. Here is the resolution.You have to delete your lockfile (
package-lock.jsonorpnpm-lock.yaml) and install your dependencies freshly.