nuxt / content

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

Cannot access 'useNitroApp' before initialization #2600

Closed Ru1ers closed 6 months ago

Ru1ers commented 6 months ago

Environment

Reproduction

Use @ nuxt/content in the nuxt project. When I use Hooks, I get an error message when starting the project:

ERROR  [worker reload] [worker init] Cannot access 'useNitroApp' before initialization                                                                                                                             16:33:49  

at <anonymous> (node_modules\.pnpm\nitropack@2.9.4\node_modules\nitropack\dist\runtime\error.mjs:5:1)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Describe the bug

/server/plugins/content.ts

export default defineNitroPlugin((nitroApp) => {
// @ts-ignore
nitroApp.hooks.hook('content:file:afterParse', (file) => {
if (file._id.endsWith('.md')) {
}
})
})

Write according to the instructions in the document

Additional context

No response

Logs

No response

pi0 commented 6 months ago

Can you please make a runnable reproduction? 🙏🏼

Ru1ers commented 6 months ago

Sorry to bother you, it's been resolved. I guess it has something to do with my local environment. After I deleted node_modules and reinstalled it, there was no problem.