nuxt / content

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

queryContent does not work as expected on Vercel #1825

Closed shoma-mano closed 1 year ago

shoma-mano commented 1 year ago

Environment

Reproduction

This is app url deployed on Vercel, and this doesn't work as the same as app deployed on StackBlitz. https://nuxt-content-reproduction.vercel.app/

This is StackBlitz ver, and works as expected. https://stackblitz.com/github/shoma-mano/nuxt-content-reproduction

Describe the bug

I have content directory like this.

content
├── city
│   └── NewYorkCity.json
└── state
    └── NewYork.json
// NewYorkCity.json
{
  "id": 1,
  "name": "New York City"
}

// NewYork.json
{
  "id": 1,
  "name": "New York"
}

and app.vue is

<script setup lang="ts">
const { data: cityInfo } = await useAsyncData('city',() => queryContent('city').where({id:1}).findOne());
const { data: stateInfo } = await useAsyncData('state',() => queryContent('state').where({id:1}).findOne());
</script>

<template>
  <main>
    <p>
      data fetched by queryContent('city').where({id:1}).findOne()
    </p>
    <p>
       {{cityInfo}}
    </p>
    <p>
      data fetched by queryContent('state').where({id:1}).findOne()
    </p>
    <p>
      {{stateInfo}}
    </p>
  </main>
</template>

This works as expected on local, but doesn't on Vercel.

Additional context

No response

Logs

No response

atinux commented 1 year ago

Could you try with nuxt-edge @shoma-mano ?

https://content.nuxtjs.org/guide/migration/edge-channel

shoma-mano commented 1 year ago

Thanks for your advice! But, It still doesn't work as expected. https://nuxt-content-reproduxtion-edge-channel.vercel.app/

Repository is here. https://github.com/shoma-mano/nuxt-content-reproduxtion-edge-channel

farnabaz commented 1 year ago

I've tried deploying your repository to Vercel and it seems to work as expected. https://nuxt-content-reproduxtion-edge-channel-sigma.vercel.app/

shoma-mano commented 1 year ago

@farnabaz The reason why my deployment didn't work well was my Edge Runtime did not support $fetch.

I didn't know the reason, I couldn't confirm function logs appeared on Vercel's Dashboard before, but Dashboard works well now and I can confirm logs like below.

image

I didn't change node version setting, and it was default v18. So I'm not sure why this error happened.

But I overrode build command to nuxt generate && node -v to confirm node version, queryContent worked as expected suddenly.It seems overriding some setting is trigger that refresh edge runtime.

Anyway, this problem is not due to this library, so it's ok to close this issue.Thanks for supporting.