Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Estimated Reading Time not Working on Next.js Website

2 replies
Last updated: Jul 4, 2022
Hello, i’m facing a pretty strange issue, and i have no idea how i can solf it.Its in a NextJS Website.

I use “estimatedReadingTime”: round(length(pt::text(body)) / 5 / 180 ),
in a query, to get as the field says the estimated reading time.

When i use this query in getStaticProps, everything works just fine and i get the estimated Reading time.
But when i use the exact same query in a API route (NextJS /api/..some endpoint) i get an error.

When i remove only this line for estimatedReadingTime, the query works, so the query and fetching works fine in the API but the calculation von the readingtime give me an error.

The error is: „queryParseError”, expected ‘)’ following function arguments

Does anyone know what could be wrong here?

Thanks
Jul 4, 2022, 12:46 PM
Are you using the same API-version both places?
Jul 4, 2022, 1:51 PM
Oh man! Thousend thanks, i didn’t set any api version, and after setting the api version for the APi endpoint, it works. Thanks
Jul 4, 2022, 2:18 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in