#Astro 5 upgrade trouble

4 messages · Page 1 of 1 (latest)

sand sierra
#

I'm trying to upgrade a project to Astro 5. It uses Starlight. In components/Head.astro, I have the following two lines:

const { slug, entry } = Astro.props;
const { title } = entry.data;

But I am getting the following error, which I did not get in Astro 4:

Cannot read properties of undefined (reading 'data')

Any ideas?

limpid harnessBOT
#

Hi @sand sierra. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, I can offer some guidance on your Astro 5 upgrade issue with Starlight. The error you're encountering is likely related to changes in how content collections are handled in Astro 5. Here are some suggestions:

  1. Update Starlight: First, make sure you've updated Starlight to the latest version compatible with Astro 5. The Starlight homepage mentions an update for Astro 5 compatibility.

  2. Content Collections API Change: Astro 5 introduced changes to the Content Collections API. The entry property might no longer be available directly as it was in Astro 4. Instead, you should use the new Content Layer API.

  3. Route Data Changes: In Starlight with Astro 5, the way you access page data has changed. According to the Starlight Route Data Reference, you should now access route data from Astro.locals.starlightRoute.

Try modifying your code like this:

---
const { slug, entry } = Astro.locals.starlightRoute;
const { title } = entry.data;
---
  1. Content Config Update: If you're using content collections, you may need to update your content configuration. The Astro 5 upgrade guide suggests moving the content config file to src/content.config.ts and updating the collection definition.

  2. Check Starlight Upgrade Guide: Look for a Starlight-specific upgrade guide for Astro 5. The Starlight homepage mentions "Learn how to upgrade" for Astro 5, which might provide more specific instructions for Starlight projects.

#

If these steps don't resolve the issue, you may need to review the full Astro 5 upgrade guide for any other breaking changes that might affect your specific setup.

Remember to back up your project before making these changes, and test thoroughly after updating.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: