Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro build crashes if any front matter fields are null #6469

Closed
1 task done
NJKode opened this issue Mar 9, 2023 · 4 comments · Fixed by #6483
Closed
1 task done

Astro build crashes if any front matter fields are null #6469

NJKode opened this issue Mar 9, 2023 · 4 comments · Fixed by #6483
Assignees

Comments

@NJKode
Copy link

NJKode commented Mar 9, 2023

What version of astro are you using?

2.1.2

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

MacOS 12.2

Describe the Bug

I have some blog posts written in Markdown with YAML front matter, e.g:

---
title: Cool post!
author:
---
Nice content!

I've also set up my Astro schemas to allow null values in my front matter.

However! Since Astro 2.1.0, if ANY of these fields are nullish (such as the author field above) , astro build will crash with the following error:

Cannot read properties of null (reading '__astro')

The problem appears to be in content/utils.ts.
In the extractFrontmatterAssets() function there is this block of code:

if (typeof curr === 'object') {
  if (curr.__astro === true) {
    // continues
  }
}

In the lovingly-crafted world of JavaScript, null is of type object.
So my null front matter fields satisfy the first if statement. 😎
However in the very next step, we try to access the __astro field on this null object - resulting in explosions. 😢

Seems like a possible fix would be to also check curr !== null.

Link to Minimal Reproducible Example

https://github.com/NJKode/astro-build-error

Participation

  • I am willing to submit a pull request for this issue.
@Princesseuh
Copy link
Member

JavaScript 🤦‍♀️

Will fix, thank you for the report!

@cjreinhardt
Copy link

Is this still happening to anyone else? I’m running into this error on a project. The linked repo above also generates an error despite this issue being closed. Will post more details shortly.

@Princesseuh
Copy link
Member

The code that was causing this error does not exist at all anymore since many versions ago. If you're encountering something similar in a current version, it is most definitely not this issue and we'd love if you could open a new issue!

@cjreinhardt
Copy link

The code that was causing this error does not exist at all anymore since many versions ago. If you're encountering something similar in a current version, it is most definitely not this issue and we'd love if you could open a new issue!

Thank you! Will do a little more investigation to make sure it’s not something I’m doing wrong, will open another issue if it seems appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants