nuxt / content

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

Prerendering fails when we use Nuxt content v2 with Nuxt 3 #1338

Open itszooper opened 1 year ago

itszooper commented 1 year ago

Environment

Nuxt CLI v3.0.0-rc.4 11:15:44 RootDir: /Users/fayaz/Opensource/logspot 11:15:45 Nuxt project info: 11:15:45


Reproduction

Open this stackblitz link - https://stackblitz.com/edit/nuxt-starter-hgwgav?file=app.vue

  1. Install the dependencies - npm install
  2. Run the dev server - npm run dev - you can see it runs fine
  3. Stop and run npm run generate - You can see the error below
    ERROR  'fetchContentNavigation' is not exported by virtual:nuxt:/home/projects/nuxt-starter-hgwgav/.nuxt/imports.mjs, imported by node_modules/@nuxt/content/dist/runtime/components/ContentNavigation.mjs

Describe the bug

I am using the useAsyncData in my setup script to retrieve data from content folder.

<script setup>
const { data: posts } = await useAsyncData('feed', () =>
  queryContent('/').find()
);
</script>

Additional context

Note, this is only happening when we use it with Nuxt content module. I created a different project without nuxt content and npm run generate worked without any issues.

Logs

ERROR  'fetchContentNavigation' is not exported by virtual:nuxt:/home/projects/nuxt-starter-hgwgav/.nuxt/imports.mjs, imported by node_modules/@nuxt/content/dist/runtime/components/ContentNavigation.mjs
itszooper commented 1 year ago

Did some digging around. Found out its related somewhere to this file node_modules/@nuxt/content/dist/runtime/components/ContentNavigation.mjs where it imports this method fetchContentNavigation(). @Tahul Any idea what to do here?

import { toRefs, defineComponent, h, useSlots } from "vue";
import { hash } from "ohash";
import { useAsyncData, fetchContentNavigation } from "#imports";
export default defineComponent({
  props: {
    query: {
      type: Object,
      required: false,
      default: void 0
    }
  },
  async setup(props) {
    const {
      query
    } = toRefs(props);
    const { data, refresh } = await useAsyncData(`content-navigation-${hash(query.value)}`, () => fetchContentNavigation(query.value));
    return {
      data,
      refresh
    };
  },
  render(ctx) {
    const slots = useSlots();
    const {
      query,
      data,
      refresh
    } = ctx;
    const emptyNode = (slot, data2) => h("pre", null, JSON.stringify({ message: "You should use slots with <ContentNavigation>", slot, data: data2 }, null, 2));
    if (slots?.empty && (!data || !data?.length)) {
      return slots?.empty?.({ query, ...this.$attrs }) || emptyNode("empty", { query, data });
    }
    return slots?.default ? slots.default({ navigation: data, refresh, ...this.$attrs }) : emptyNode("default", data);
  }
});
itszooper commented 1 year ago

@danielroe Could you please help me with this?

Completely lost as to why this is breaking. A hotfix until an official fix is released?

danielroe commented 1 year ago

I haven't looked into this, but it might be fixed by https://github.com/nuxt/framework/pull/5763.

vinayakkulkarni commented 1 year ago

Go to: https://vinayakkulkarni.dev

If you go to the blog link & then navigate to main page by clicking on the logo on the top, the main screen/page content isn’t shown :(

Repo source code: https://github.com/vinayakkulkarni/vinayakkulkarni.dev

Using Nuxt 3 w/ Nuxt content v2 deployed to netlify

danielroe commented 1 year ago

I wonder if this is linked to https://github.com/nuxt/nuxt.js/issues/14325.

AlexBa commented 1 year ago

I have the same issue on Vercel (using RC 10)

AlexBa commented 1 year ago

Same problem with local environment. I additionally tried Nuxt 3 RC 11