Cannot fetch data

I am brand new to Prismic. I have an existing Vue site with Nuxt. I have done the basics for setup but when I get to the "fetch" part of the documentation, I get stuck.

For some reason, I cannot get any data from "$prismic" it comes back undefined.

My nuxt.config.js matches the "crash course" but I can't seem to get data to be fetched.

I also copied the block of code that fetches the data. I get " Cannot read properties of undefined (reading 'api')"

What am I missing?

Hello @mitchel, can you show us exactly where you got stuck in the guide?
How are you creating your page queries?

I get to the "fetch data" section.

export default {
async asyncData({ $prismic, params, error }) {
const document = await $prismic.api.getByUID('page', params.uid)

if (document) {
  return { document }
} else {
  error({ statusCode: 404, message: 'Page not found' })
}

}
}

It bombs on the "$prismic" part. I try to console.log it, and it comes back undefined.

This should work just fine if you are using the latest version of the kit.
Are you still experiencing this error?

I have the same problem, I created a new nuxt project entirely and the pluggin itself seems to break. I looked at prismic.js and it's not initializing the client correctly, so it crash everytime, I initialized my own prismic.js and injected $prismicCustom where I initialise prismic client correctly (using prismic.createClient instead of just prismic.client) and it works, but it's something that should be updated on the plugin.

I tried with an older version of nuxtjs/prismic like one of the starter and it works fine, but the latest version does not work, and the documentation seems way off, I'm thinking about using another headless CMS just because of this, Prismic seems cool but not having a functionnal documentation makes it hard to start.

Which version of Nuxt are you creating this with? fetching content in Nuxt3 is handled differently.

Can you post your Nuxt config and package.json files?

1 Like

I was on Nuxt 2. We are moving to Nuxt 3 and Vue 3 now as a result.

Hello everyone. The DevX has some follow-up for your questions:

@mitchel and @sebpaquets could you please share more info about your setup?

  • Nuxt version
  • Nuxt Prismic module version
  • Nuxt configuration, anything he thinks could be helpful, a
  • Also, the steps to be able to make a minimal reproduction can be useful as well.

@sebpaquets is it possible that you used the Nuxt 2 module on a Nuxt 3 app?