Closed igorskyflyer closed 1 year ago
I keep getting The required prop post is not valid, aborting now.
.
Im in Astro 2.0. Is that expected or am i just doing it wrong? :)
I keep getting
The required prop post is not valid, aborting now.
.Im in Astro 2.0. Is that expected or am i just doing it wrong? :)
Sorry that you're getting this issue but could you provide a way for me to reproduce the issue or at least look at your code, via a repository, code snippet, etc.
💡 But here is some insight first - as described in the component's README:
Post - this prop represents the post whose excerpt you want to generate and render, usually obtained via
Astro.glob()
, thus, you should insert this component inside your posts loop, seeAstro API
for more info.If this prop is not supplied or not valid, the component will throw an error.
Meaning you should insert this component inside your posts loop, like seen here on my own Astro site:
Judging by the error you're getting - without seeing the code - it seems like you're either not rendering the component inside your posts loop or the provided prop post
is of the wrong type.
I can tell you more if you provide me a reproducible code/site. 😚
Note: Astro v2 shouldn't cause this, judging by their migration guide.
this is my PostPreview.astro
https://gist.github.com/bronze/e47ee1490190bd6b3609644349d2feec
a bit of a frankenstein im afraid :)
im thinking maybe its something on here?
const {
post: {data: post, slug},
} = Astro.props
ps: thank your for responding
this is my
PostPreview.astro
gist.github.com/bronze/e47ee1490190bd6b3609644349d2feec a bit of a frankenstein im afraid :) im thinking maybe its something on here?const { post: {data: post, slug}, } = Astro.props
ps: thank your for responding
Ah, yes, looking at your code, specifically lines:
I can see what's wrong, as I mentioned earlier, you're passing a prop of the CollectionEntry
type instead of a prop of MarkdownInstance<Record<string, any>>
type. This was a breaking change introduced in Astro v2 indeed that occurred when you switched to Collections.
Markdown documents fetched with Astro.glob()
function - the old way - are of the proper MarkdownInstance<Record<string, any>>
type.
I haven't played with the new Astro but I am curious though 🤔 on line 11 what does post.data
contain and what its type?
You could try now on line 45:
<PostExcerpt post={post.data} words={20} addEllipsis={false} />
Does that work? This is just a theory.
If that doesn't work then Astro has made even more breaking changes and you'll have to wait until I release the new version that's compatible with Astro v2. 😌
Trying post.data breaks everything. I really dont know what the data is doing there, actually. I was trying to make pagination work and i got that from a theme on the astro.build site. here it is: https://github.com/one-aalam/astro-ink/blob/58be5b256ae5f0f0bf90cf140e41046873f949ff/src/components/PostPreview.astro from the Astro Ink Theme
Trying post.data breaks everything. I really dont know what the data is doing there, actually. I was trying to make pagination work and i got that from a theme on the astro.build site. here it is: one-aalam/astro-ink@
58be5b2
/src/components/PostPreview.astro from the Astro Ink Theme
Well, at least we tried 😅 That's why I said it's just a thought. Anyway, now we can be certain that the Collections break the old behavior of Markdown files. 😕
I'll have to implement a solution that works with Astro v2, as intended in this issue. 🤓
Sorry that we couldn't fix it on-the-fly here. 😪
No problem! Thank you very much for taking your time on it! :D
No problem! Thank you very much for taking your time on it! :D
Sure, no problem! I'll be looking into converting my site to Astro v2 and solving this issue, tomorrow hopefully. 🤩
Thanks for your feedback and for using my component. 🤗
🚀 Follow v2 migration guide Astro v2 migration guide. 👨🏼🚀
No problem! Thank you very much for taking your time on it! :D
@bronze, I've released a new version that works with both Astro \<v2 and Astro >=v2, upgrade my component in your package, and inform me if it works for you now. 🤩
🚀 Astro v2 upgrade 👨🏼🚀
/src/content
Astro.fetchContent()