#Error during build with slot element - 'Cannot read properties of 'null' (reading 'default')'

4 messages · Page 1 of 1 (latest)

drowsy kettle
#

When I run the build command with my problematic code, during build time I get this error:

TypeError: Cannot read properties of null (reading 'default')

After a bit of digging, I found out that the <slot> element in layouts\main.astro is causing the issue, however, I don't know why - the basics template has an <slot> element and that works just fine...

A repository of the problematic code: https://github.com/alipex/SlotIssueAstro

Any ideas for a fix? Thank you!

GitHub

Contribute to alipex/SlotIssueAstro development by creating an account on GitHub.

idle summit
#

Hi there!

The issue here is with your project's folder structure.

You need to have the layouts directory live outside of the pages directory, because all .astro files in the pages directory are built as individual pages in the build process.

#
├── src/
│   ├── layouts/
│   │   └-─ main.astro
│   └── pages/
|       ├── index.astro

This will work, but don't forget to update the path to import your layout in the index.astro file to match. In this case, it would look like:
index.astro:

---
import Main from '../layouts/main.astro';
---

<Main Title='Test'>Test!</Main>

By the way -- I don't think it's recommended to declare props with an initial capital letter, so I would change your "Title" prop to "title".

drowsy kettle
#

Ah, so there's the problem. Just tried the fix and it worked. Thanks!