NuxtN
Nuxt10mo ago
41 replies
erztemplerobba

Nuxt content v2 -> v3

Nuxt version ^3.16.2:
  future: {
    compatibilityVersion: 4
  },
compatibilityDate: '2024-07-11'


I've updated nuxt content to 3.4.0. my content files are in root/content and I've always used this code to load my data. In this case root/content/general.md:
const { data: general } = await useAsyncData("general", () =>
  queryContent("general").findOne()
);

if (!general.value) {
  throw createError({
    statusCode: 404,
    statusMessage: "Content Data Page not found",
    fatal: true,
  });
}


In the migration guide, I read that content files don't have to be modified. Using this, my app throws the error: Content Data Page not found. Also, queryContent("/").findOne() does return undefined.

Next, I've tried using collections:
const { data: page } = await useAsyncData('general', () => {
  return queryCollection('general').path('/').first()
})


with the content.config.ts looking like this:
import { defineCollection, defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
  collections: {
    docs: defineCollection({
      source: '**/*.md',
      type: 'data', // also tried 'page'
    }),
  },
})


Neither approach works, my .md (also tried .yml) content files cannot be found. Help would be much appreciated.
Was this page helpful?