Cannot Read Properties of Unndefined ('data') Sveltekit

Describe your question/issue in detail

So I an currently going through a prismic tutorial "Course-Resources-Dark-Modern-Website" to try and learn the technology and how it integrates with Svelte.

I am at the point where I need to use a Custom Type in order to access the data properites of my SettingsDocument.

I used the following suggested menth to import the custom type but this fails and the intellisense doesnt pcik upthe properties and the code fails on 500.

`/** @type {import("@prismicio/client").Content.SettingsDocument} */
export let settings;
<span class="sr-only">{settings.data.website_title}</span>

`

So i then tried this approach:

import type { SettingsDocument } from '../../prismicio-types';
export let settings:SettingsDocument;
<span class="sr-only">{settings.data.website_title}</span>

However from both approaches I get the same error as shown below, even though the second approach does start picking up the proper data. types in the intellisense, Any ideas where im going wrong here?

[vite:dev] TypeError: Cannot read properties of undefined (reading 'data')
[vite:dev]     at Footer (/home/src/lib/components/Footer.svelte:15:45)

Hey @davytliverpool,

Could you provide a bit more context and maybe host your code on github so that we can help you debug it.

It is possible that you're not getting the data that are expected to be rendered.
So it could be that you haven't publish the Prismic Document to make it available in your API.
That you're not querying properly that document and/or returning the data properly.

It can also be something completely different and having access to the code will help us greatly.

Cheers,
Renaud

Thanks @renaud

I have managed to find the issue it was due to the fact that I wasn't passing the data across correctly :persevere: I have now correctly this and its working :sunglasses:

Thanks for the help :wink:

1 Like