Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production Build: queryContent Triggers 500 Internal Server Error #2580

Closed
santiagoaloi opened this issue Mar 5, 2024 · 15 comments
Closed

Comments

@santiagoaloi
Copy link

santiagoaloi commented Mar 5, 2024

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: [email protected]
  • Builder: -
  • User Config: devtools, modules, content
  • Runtime Modules: @nuxt/[email protected]
  • 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

No tasks being tracked yet.
@staaph
Copy link

staaph commented Mar 5, 2024

Additionally

const { data } = await useAsyncData('articles', () => queryContent('/articles').find())

running this in production, while owning a /content/articles folder with .md files in it, returns an empty Array.

@ptdev
Copy link

ptdev commented Mar 5, 2024

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:

"resolutions": {
    "nitropack": "2.8.1"
}

Using yarn v4 with nodeLinker: node-modules

@santiagoaloi
Copy link
Author

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:

"resolutions": {
    "nitropack": "2.8.1"
}

Using yarn v4 with nodeLinker: node-modules

Using resolutions and [email protected] indeed resolves the issue. I appreciate you sharing this workaround. 👍

johannschopplich added a commit to kirby-tools/kirbyseo.com that referenced this issue Mar 7, 2024
@farnabaz
Copy link
Member

farnabaz commented Mar 7, 2024

Seems that Nitro generate different kind of chunk for JSON files.

Screenshot 2024-03-07 at 14 57 01

Maybe @pi0 could help us on this

@johannschopplich
Copy link

This issue is resolved in the latest Nitro version (v2.9.3).

For reference: nitrojs/nitro#2239.

We can all remove the resolutions override and use the latest Nitro version again. 🙂

@luminous8
Copy link

How to update the nitro version? i dont see nitro in my package.json 🤔

@johannschopplich
Copy link

How to update the nitro version? i dont see nitro in my package.json 🤔

You have to delete your lockfile (package-lock.json or pnpm-lock.yaml) and install your dependencies freshly.

@mklueh
Copy link

mklueh commented Mar 14, 2024

Could this be related somehow? #2378

@tahirmahmudzade
Copy link

tahirmahmudzade commented Mar 21, 2024

I'm using nitropack: 2.9.4 which is the latest and getting this error during build:

 Prerendering 1 routes                                                                                                    nitro 3:45:45 PM
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM
Errors prerendering:
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM

 ERROR  Exiting due to prerender errors.  

any idea ?

@joppehoekstra
Copy link

I'm also on [email protected], getting the following error when running nuxt generate:

ERROR  Entry module "../node_modules/.pnpm/[email protected]/node_modules/nitropack/dist/runtime/entries/nitro-prerenderer" cannot be external.
  at getRollupError (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:376:41)
  at error (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:372:42)
  at ModuleLoader.loadEntryModule (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18918:20)
  at async Promise.all (index 0) 

@ra-jeev
Copy link

ra-jeev commented Apr 4, 2024

I'm using nitropack: 2.9.4 which is the latest and getting this error during build:

 Prerendering 1 routes                                                                                                    nitro 3:45:45 PM
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM
Errors prerendering:
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM

 ERROR  Exiting due to prerender errors.  

any idea ?

Hi @tahirmahmudzade,
I've the same error. Did you find any fix for the issue? I'm on the latest [email protected].

@santiagoaloi
Copy link
Author

I'm using nitropack: 2.9.4 which is the latest and getting this error during build:

 Prerendering 1 routes                                                                                                    nitro 3:45:45 PM
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM
Errors prerendering:
  ├─ /api/_content/cache.1711021521779.json (14ms)                                                                          nitro 3:45:45 PM
  │ └── Error: [500] 
                                                                                                                            nitro 3:45:45 PM

 ERROR  Exiting due to prerender errors.  

any idea ?

Hi @tahirmahmudzade, I've the same error. Did you find any fix for the issue? I'm on the latest [email protected].

Could you share yournuxt.configfile?

@ra-jeev
Copy link

ra-jeev commented Apr 5, 2024

Here is my nuxt.config.ts

export default defineNuxtConfig({
  modules: ['@nuxthub/core', '@nuxt/ui', '@nuxt/image', '@nuxt/content'],
  devtools: { enabled: true },
  image: {
    format: ['avif', 'webp'],
  },
});

and package versions in package.json

"dependencies": {
  "@nuxt/content": "^2.12.1",
  "@nuxt/image": "^1.5.0",
  "@nuxt/ui": "^2.15.1",
  "@nuxthub/core": "^0.4.0",
  "nuxt": "^3.11.2"
},
"devDependencies": {
  "@nuxt/eslint-config": "^0.2.0",
  "eslint": "^8.57.0",
  "vue-tsc": "^2.0.7",
  "wrangler": "^3.45.0"
}

Below is the build log on my local machine

ℹ Initializing prerenderer                                      nitro 12:56:52 AM
ℹ Prerendering 1 routes                                         nitro 12:56:58 AM
  ├─ /api/_content/cache.1712258784361.json (9ms)                nitro 12:56:58 AM
  │ └── Error: [500]
                                                                 nitro 12:56:58 AM
Errors prerendering:
  ├─ /api/_content/cache.1712258784361.json (9ms)                nitro 12:56:58 AM
  │ └── Error: [500]
                                                                 nitro 12:56:58 AM

 ERROR  Exiting due to prerender errors.                               12:56:58 AM

  at prerender (node_modules/nitropack/dist/chunks/prerender.mjs:218:11)
  at async node_modules/nuxt/dist/index.mjs:3471:7
  at async build (node_modules/nuxt/dist/index.mjs:5001:5)
  at async Object.run (node_modules/nuxi/dist/chunks/build.mjs:95:5)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1648:16)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1639:11)
  at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1777:7)



 ERROR  Exiting due to prerender errors.                               12:56:58 AM

error: script "build" exited with code 1

@santiagoaloi
Copy link
Author

This issue is resolved in the latest Nitro version (v2.9.3).

Perfect, this settles the issue then.

@ra-jeev
Copy link

ra-jeev commented Apr 9, 2024

Here is my nuxt.config.ts

export default defineNuxtConfig({
  modules: ['@nuxthub/core', '@nuxt/ui', '@nuxt/image', '@nuxt/content'],
  devtools: { enabled: true },
  image: {
    format: ['avif', 'webp'],
  },
});

and package versions in package.json

"dependencies": {
  "@nuxt/content": "^2.12.1",
  "@nuxt/image": "^1.5.0",
  "@nuxt/ui": "^2.15.1",
  "@nuxthub/core": "^0.4.0",
  "nuxt": "^3.11.2"
},
"devDependencies": {
  "@nuxt/eslint-config": "^0.2.0",
  "eslint": "^8.57.0",
  "vue-tsc": "^2.0.7",
  "wrangler": "^3.45.0"
}

Below is the build log on my local machine

ℹ Initializing prerenderer                                      nitro 12:56:52 AM
ℹ Prerendering 1 routes                                         nitro 12:56:58 AM
  ├─ /api/_content/cache.1712258784361.json (9ms)                nitro 12:56:58 AM
  │ └── Error: [500]
                                                                 nitro 12:56:58 AM
Errors prerendering:
  ├─ /api/_content/cache.1712258784361.json (9ms)                nitro 12:56:58 AM
  │ └── Error: [500]
                                                                 nitro 12:56:58 AM

 ERROR  Exiting due to prerender errors.                               12:56:58 AM

  at prerender (node_modules/nitropack/dist/chunks/prerender.mjs:218:11)
  at async node_modules/nuxt/dist/index.mjs:3471:7
  at async build (node_modules/nuxt/dist/index.mjs:5001:5)
  at async Object.run (node_modules/nuxi/dist/chunks/build.mjs:95:5)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1648:16)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1639:11)
  at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.9edf0930.mjs:1777:7)



 ERROR  Exiting due to prerender errors.                               12:56:58 AM

error: script "build" exited with code 1

For this one I had raised an issue in the @nuxthub/core repo. Here is the resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants