#Slugs not generated by build, but are fine in dev

3 messages · Page 1 of 1 (latest)

fast kelp
#

I've got a content collection named 'blog'. When I run my website locally with astro dev, the routes generated by my [...slug].astro exist and I can view those pages. However, when I run astro build, those routes aren't generated.

After a little testing, I've found that components that call getCollection (as in the below code) get results and are rendered correctly.

const featuredBlogPosts = await getCollection(
  'blog',
  (entry) => entry.data.featured && entry.data.featured > 0
)

But the getCollection within getStaticPaths is returning no entries. Oddly, it does return entities for a separate data collection.

export async function getStaticPaths() {
  const blogEntries = await getCollection('blog')

  const gearEntries = await getCollection('gear')

  console.log(`Found ${blogEntries.length} blog entries`)
  console.log(`Found ${gearEntries.length} gear entries`)

  return blogEntries.map((entry) => ({
    params: { slug: entry.slug },
    props: { post: entry },
  }))
}

The console.log's in the getStaticPaths above generate:

▶ src/pages/blog/[...slug].astro
Found 0 blog entries
Found 6 gear entries
tawdry jacinth
#

Sounds odd! Any chance you’re mutation the entries returned by a getCollection('blog') call somewhere in your code base? I’ve seen that cause issues before, although I’d expect the issues to be visible during dev as well 🤔

fast kelp
#

I'll bet that's exactly what's happening. I'm doing some funky stuff on my /blog/index.astro page. Let me check.