✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Error with Promise.prototype.then in client.js causing frustration, seeking help.

12 replies
Last updated: Jan 17, 2023
I get the following error: Uncaught TypeError: Method Promise.prototype.then called on incompatible receiver #<Promise> at Proxy.then (<anonymous>)

I ask here because my chrome console says the error comes from client.js (where I create the client). Been trying to fix this for a while and it's becoming quite annoying, help would be really appreciated.
Jan 16, 2023, 9:30 AM
Are you using a .then method on the client when fetching the data.
Jan 16, 2023, 2:40 PM
Can you post it's use here?
Jan 16, 2023, 2:41 PM
user S
Jan 16, 2023, 4:04 PM
user S
Pretty sure the only place I'm fetching data using client is in my page.js file, bellow is the code.

 const projects = await client.fetch(`*[_type == "project"]`)
  const articles = await client.fetch(`*[_type == "article"]`)
  const faqs = await client.fetch(`*[_type == "faq"]{..., faq_category->}`)
  const testimonials = await client.fetch(`*[_type == "testimonial"]`)
Jan 16, 2023, 4:05 PM
You are importing the client right? Can't see the top
Jan 16, 2023, 4:25 PM
Also I would put the fetch methods in a getStaticProps method and pass into the component as props.
Jan 16, 2023, 4:27 PM
Your code seems quite complicated. I would try to compartmentalize it as much as I could to determine where the error is coming from. Perhaps remove the fetch methods and comment out the code using them and bring them back one by one. Also having them in a function whether getServerSideProps or getStaticProps would be much better for troubleshooting.
Jan 16, 2023, 4:32 PM
Yes, it's being imported at the top of the page. I'm using next 13 so getStaticProps no longer exists.
I'm fetching data In the simplest way and a way that's recommended in next 13 docs. I think the code is fairly simple.

Unfortunately I tried your suggestion and it's still not working.
Jan 16, 2023, 5:08 PM
Then the issue isn't in the fetch function. There is another promise executing somewhere.
Jan 16, 2023, 5:29 PM
I'm really not sure where
Jan 17, 2023, 9:34 AM
It looks like you’re chaining a
somewhere to a fetch somewhere?
Jan 17, 2023, 7:36 PM
Hi RD, I have just fixed this and honestly I don't know how. I just rebuilt the project
Jan 17, 2023, 8:42 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?