KSPR
KSPR

Reputation: 2375

how to import nuxt/content correctly?

I try to display a markdown file from content to some page and no matter what I do I get this error:

[plugin:vite:import-analysis] Failed to resolve import "#content" from "pages/info.vue". Does the file exist?

template:

<script setup>
import { queryContent } from "#content";
const { data: infoDisclaimer } = await queryContent("/infoDisclaimer").findOne();
</script>

<template>
  <NuxtContent :document="infoDisclaimer" />
</template>

infoDisclaimer.md

hello

nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2024-11-01',
  devtools: { enabled: true },
  modules: ['@nuxt/content']
})

content.config.ts

import { defineContentConfig } from '@nuxt/content'

export default defineContentConfig({
  // If you're manually creating pages, you might want to disable document-driven mode.
  documentDriven: false,
  // You can also customize markdown options here.
  markdown: {
    remarkPlugins: [],
    rehypePlugins: []
  }
})

I checked if it si installed:

npx nuxi info

Working directory: /path/project                                                                                        nuxi  12:11:04
Nuxt project info: (copied to clipboard)                                                                                                                                     nuxi  12:11:04

------------------------------
- Operating System: Darwin
- Node Version:     v22.2.0
- Nuxt Version:     3.15.4
- CLI Version:      3.22.2
- Nitro Version:    2.10.4
- Package Manager:  [email protected]
- Builder:          -
- User Config:      compatibilityDate, devtools, modules
- Runtime Modules:  @nuxt/[email protected]
- Build Modules:    -
------------------------------

I also tried to import it like this:

<script setup>
import { queryContent } from "@nuxt/content";
const { data: infoDisclaimer } = await queryContent("infoDisclaimer").findOne();
</script>

then at least I get another error:

[plugin:vite:import-analysis] Importing directly from module entry-points is not allowed. [importing @nuxt/content from pages/info.vue]

What else is there? Didn't expect it to be this hard.

Upvotes: 0

Views: 26

Answers (0)

Related Questions