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

queryContent doesn't work after nuxt build #2593

Open
kevinhaeni opened this issue Mar 23, 2024 · 12 comments
Open

queryContent doesn't work after nuxt build #2593

kevinhaeni opened this issue Mar 23, 2024 · 12 comments

Comments

@kevinhaeni
Copy link

kevinhaeni commented Mar 23, 2024

Environment

"@nuxt/content": "^2.12.0",
"nuxt": "^3.10.2",
"vue": "^3.4.19",

Reproduction

  • content/
  • -- doc_1.json
  • -- doc_2.json
  • app.vue
  • nuxt.config.ts
  • pages/
  • -- [...slug].vue

slug.vue:

const slug = route.params.slug[0];
const { data, pending, error, refresh } = await useAsyncData(slug, () => queryContent(slug).findOne());

nuxt.config.ts:

import path from "node:path";

export default defineNuxtConfig({
  ssr: true,
  modules: [
    '@nuxt/content'
  ],
  content: {
    content: {
      driver: 'fs',
      base: path.resolve(__dirname, 'content')
    },
  },
  routeRules: {
    "/**": {
      prerender: false,
    },
  },
});

Describe the bug

When running nuxt dev, everything works fine: calling localhost:3000/doc_1 shows the content of doc_1.json:

However, when running nuxt build and node .output/server/index.mjs and doing the same request, I'm getting:

[nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading '_path')
  at ./.output/server/chunks/nitro/node-server.mjs:8163:52  
  at Array.find (<anonymous>)  
  at fetchDirConfig (./.output/server/chunks/nitro/node-server.mjs:8163:32)  
  at ./.output/server/chunks/nitro/node-server.mjs:8197:63  
  at Array.reduce (<anonymous>)  
  at ./.output/server/chunks/nitro/node-server.mjs:8197:39  
  at async Object.handler (./.output/server/chunks/nitro/node-server.mjs:8528:21)  
  at async Object.handler (./.output/server/chunks/nitro/node-server.mjs:2967:19)  
  at async toNodeHandle (./.output/server/chunks/nitro/node-server.mjs:3233:7)  
  at async ufetch (./.output/server/chunks/nitro/node-server.mjs:3599:17)

I would expect that queryContent fetches the files from /content directory. I could swear that some days ago it did fetch data from some nuxt-content cache file (which would also not be good as my data in /content is dynamic.

Additional context

What confuses me is that under .output/server/chunks/raw/ I see a doc_1.mjs and a doc_2.mjs and the error seems to result from loading these files.

Logs

No response

@kevinhaeni kevinhaeni changed the title queryContent doesn't work after nuxt build with queryContent doesn't work after nuxt build Mar 23, 2024
Copy link
Member

farnabaz commented Mar 23, 2024

Do you mind creating a simple reproduction using the starter? https://nuxt.new/c/content

@kevinhaeni
Copy link
Author

I tried but even when I run build in the unmodified starter, I'm getting a:
[8:35:59 PM] ERROR Nuxt Build Error: "joinRelativeURL" is not exported by "node_modules/ufo/dist/index.mjs", imported by "virtual:nuxt:/workspace/.nuxt/paths.mjs".

@Ahmard
Copy link

Ahmard commented Mar 25, 2024

Try upgrading your Nuxt version, it'll work,
nuxi upgrade --force

@some-user123
Copy link

Try pnpm up ufo (or corresponding command in your package manager).

@kevinhaeni
Copy link
Author

thanks! Here you go: Sample

When using nuxt dev and opening :3000/doc_1
it works, when doing the same after nuxt build and node .output/server/index.mjs, I'm still getting the error [nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading '_path')

@juane1000
Copy link

Can confirm that a nuxi upgrade did the trick. Experienced the issue for the first time today. I was on the current version however. Not sure what went wrong.

@santiagoaloi
Copy link

I would assume its related to a an issue I reported some time ago #2580
Upgrading nuxt to the latest version will also upgrade nitro pack the bug I was hitting was related to Nitro Version: 2.9.1
If this case is resolved, I suggest closing it 🙂

@kevinhaeni
Copy link
Author

I did a npx nuxi upgrade and it's now using: Nuxt 3.11.2 with Nitro 2.9.6
However, the error still persists for me

@idesignzone
Copy link

idesignzone commented Apr 12, 2024

I have this problem too. Following

const { data } = await useAsyncData(slug, () => queryContent(slug).findOne());

works in Dev but not in Prod. Seems like it takes a moment for content to load and gets ignored in process. After a page reload content appears!

"nuxt": "^3.11.2",
"@nuxt/content": "^2.12.1",

@ABB65
Copy link

ABB65 commented Apr 25, 2024

Unfortunately I have the same error.
While the code below works in dev mode on my blog pages that I prerender with route rules and on the pages I created for some static documents, it does not work after build.

const { data: documents } = await useAsyncData('contracts-kvkk-data', () =>
  queryContent<any>('/sozlesmeler-ve-kvkk').find())

This code gives me an empty array after build.

Route rules are as follows.

    'sozlesmeler-ve-kvkk/**': {
      prerender: true,
    },

@EroTiXx

This comment was marked as resolved.

@cameroncf
Copy link

cameroncf commented May 7, 2024

I tried but even when I run build in the unmodified starter, I'm getting a:
[8:35:59 PM] ERROR Nuxt Build Error: "joinRelativeURL" is not exported by "node_modules/ufo/dist/index.mjs", imported by "virtual:nuxt:/workspace/.nuxt/paths.mjs".

@kevinhaeni I'm getting this same error and did a little digging in the lockfile to try and find it's origin. Looks like ufo@1.4.0 doesn't export joinRelativeURL but ufo@1.5.3 does. Both are in my lockfile, and they seem to track back to a specific version of Rollup and/or Nuxt, but then my head exploded trying to get further.

Did you ever find a resolution to this?

Edit: Adding a solution that just worked for me.

  1. Added the below override to package.json
  2. Deleted node_modules
  3. Ran pnpm i
"overrides": {
  "nuxt": {
    "ufo": "1.5.3"
  }
},

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