nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.13k stars 627 forks source link

Nuxt content causing an infinite build process with mongoose in nitro plugins #2407

Closed GalacticHypernova closed 5 months ago

GalacticHypernova commented 1 year ago

Environment


Reproduction

https://stackblitz.com/edit/github-ftqn23?file=pages%2F[...slug].vue,nuxt.config.ts,server%2Fplugins%2Fstartup.ts

Other prerequisites:

  1. Must have a valid mongodb database connection present on the local machine set on localhost with port 27017 with a database called "test"
  2. Must run it on the local machine, as that's where the issue is present (tested specifically on ubuntu. but I doubt that much can make a difference)

For more information, please refer to https://discord.com/channels/473401852243869706/1002541842409193563/1168471513842864128 (in the Nuxt discord)

Describe the bug

When using @nuxt/content, during the server build process the prerenderer gets initialized to prerender routes. This causes the server plugins to execute, which run ~/server/plugins/startup.ts. When the connection is valid and runs as expected, it is connected before the build is done, and when the build process finally reaches the ending message of "you can preview this build...." it never actually finishes, and the build must be stopped using ctrl + c, otherwise it hangs indefinitely.

Additional context

The plugin appears to run correctly but during the hang there are no error messages, which make it extremely hard to debug. If this cannot be reproduced, I would happily share my screen showcasing the behavior.

Logs

No logs are given, no error messages, nothing.
GalacticHypernova commented 5 months ago

For anyone else who may experience this, here is the solution that seems to have worked for me (and no, I am not even kidding, this is the only way I managed to resolve this):

console.log("HELLO THERE")
console.log(import.meta.prerender, import.meta.dev, import.meta.test, import.meta.env?.PROD)
if(!import.meta.prerender){
// Handle mongoose connection here
}

Without the console.logs it had still presented the same issue, which is why they are needed for this fix to work (again, at least in my case)

@farnabaz this likely isn't intended behavior, right?