Troubleshooting a query error in an Airbnb clone tutorial
16 replies
Last updated: Oct 14, 2021
A
Hi, I'm currently following the amazing tutorial for an airbnb clone on youtube by
I then get this error: (I changed the props names to fit my project, so properties=terrain for me, but everything else is typed the same). I'm thinking maybe it's an API version issue? Thanks
user S
but I'm stuck on the part where she queries the pageSlug: `const query = `*[ _type == "terrain" && slug.current == $pageSlug][0]{
Oct 12, 2021, 12:42 PM
R
Hey there! Is this happening for all queries or just this particular one? How have you configured your Sanity client?
Oct 12, 2021, 5:39 PM
A
Hi, thanks for your reply! Well it's the first query I've written and I can't move on to the next step of writing the code because I'm stuck here... this is how i set up the client (i did not put the ID in a .env file because for some reason the file wasn't being read by the project so I'm leaving it in sanity.js for now)
Oct 13, 2021, 9:15 AM
R
Got it. I think I see the issue. For now, can you get the query to work if you remove the environment variables entirely and just hardcode your project ID and dataset name?
Oct 13, 2021, 5:56 PM
R
Then we can work on getting your .env working properly!
Oct 13, 2021, 5:57 PM
A
So I should write it as dataset: "production" and remove the process.env entirely?
Oct 13, 2021, 8:15 PM
A
Also is the apiversion date correct? or should i update it to something more recent?
Oct 13, 2021, 8:15 PM
R
That version date is fine! And yes, totally remove any process.env stuff for now.
Oct 13, 2021, 8:19 PM
A
unfortunately I still get the same error, if I changed the sanity.js file right (ClientError: Unable to parse value of "$pageSlug=undefined". Please quote string values.)
Oct 13, 2021, 8:34 PM
R
Can you share the repo for this?
Oct 13, 2021, 8:36 PM
Could you check your studio and ensure every person and every property has a slug, and that those documents (containing slugs) are published?
Oct 13, 2021, 10:09 PM
A
here is the repo https://github.com/serenity-innovation/peloimmo/tree/main/peloimmo
user M
user A
yes I've checked and every document has a slug and is published, but not all the fields in the studio have data (i didnt upload all the images for exemple), could this be an issue?Oct 14, 2021, 1:36 PM
R
Can you try changing this line to:
const pageSlug = pageContext.query.slug?
Oct 14, 2021, 3:35 PM
Might also need to comment out the
file: terrain.filesline in your return. It’s causing an issue.
Oct 14, 2021, 3:37 PM
A
everything is now working! thank you so much 🙏
Oct 14, 2021, 7:04 PM
R
Awesome!
Oct 14, 2021, 7:27 PM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.