0

So, I have data which needs to be revalidated from a Firebase Realtime database. Everything works fine when I go for yarn run build and then yarn run start. But when I deploy the website to Vercel, the data does not get revalidated. How can I fix it?

Here is the function:

export async function getStaticProps({ params: { postname } }) {
  const fileName = readFileSync(`posts/${postname}.md`, 'utf-8')
  const { data: frontmatter, content } = matter(fileName)
  const snapshot = await retrieveComments(postname).then(snapshot => {
    return { props: { snapshot } }
  })
  const slug = postname

  return {
    props: {
      frontmatter,
      content,
      snapshot,
      slug
    },
    revalidate: 5
  }
}
Kul
  • 3
  • 3

1 Answers1

1

Try with the combination of getStaticPaths()

export async function getStaticPaths() {

  // We'll pre-render only these paths at build time.
  // { fallback: 'blocking' } will server-render pages
  // on-demand if the path doesn't exist.
  return { paths:[], fallback: 'blocking' }
}

and after that use

export async function getStaticProps({ params: { postname } }) {
  const fileName = readFileSync(`posts/${postname}.md`, 'utf-8')
  const { data: frontmatter, content } = matter(fileName)
  const snapshot = await retrieveComments(postname).then(snapshot => {
    return { props: { snapshot } }
  })
  const slug = postname

  return {
    props: {
      frontmatter,
      content,
      snapshot,
      slug
    },
    revalidate: 5
  }
}
Singh
  • 783
  • 1
  • 6
  • 24
  • Hello! This one seems to be really witty. But there is just one error appearing: `Can't resolve 'fs'` – Kul Mar 02 '23 at 12:18
  • Here is the import: `import { readdirSync, readFileSync } from 'fs'` – Kul Mar 02 '23 at 12:19