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.
AI Update

This is a tricky error that can be frustrating to debug! The Promise.prototype.then called on incompatible receiver error typically happens when there's a mismatch in how promises are being handled, often related to how the Sanity client is imported or configured.

Based on similar issues in the community, here are the most common causes and solutions:

Most Likely Causes

1. Client Import/Export Issue

Make sure you're exporting and importing your Sanity client correctly. Your client.js file should look like this:

import { createClient } from '@sanity/client'

export const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  useCdn: true,
  apiVersion: '2023-05-03',
})

Then import it with:

import { client } from './path/to/client'

2. Mixing Promise Patterns

Since you're using Next.js 13 with async/await (which is correct), make sure you're not accidentally chaining .then() anywhere in your code. Your fetch pattern looks correct:

const projects = await client.fetch(`*[_type == "project"]`)

3. Build Cache Issues

This error sometimes resolves after rebuilding the project. Try:

# Delete build artifacts
rm -rf .next
rm -rf node_modules/.cache

# Reinstall and rebuild
npm install
npm run dev

4. Multiple Client Instances

Check if you're accidentally creating multiple client instances or if there's a conflict with how the client is being proxied. Make sure you're only creating one client instance and reusing it throughout your app.

5. Next.js 13 App Router Specifics

If you're using the App Router, ensure your component is properly marked as async and you're not mixing server/client components incorrectly. Server components (the default) should use async/await directly, while client components need 'use client' at the top.

Additional Debugging Steps

  • Check your browser's Network tab to see if the Sanity API requests are actually succeeding
  • Look for any other promise-related code in your files that might be interfering
  • Make sure your @sanity/client package is up to date: npm install @sanity/client@latest
  • Verify you don't have conflicting versions of the Sanity client installed
  • Try temporarily simplifying your queries to just one fetch to isolate the issue

The error pointing to client.js in Chrome's console can sometimes be misleading - the actual issue might be in how the client is being used elsewhere in your code, not in the client configuration itself.

If the problem persists after trying these solutions, I'd recommend sharing your exact client.js configuration and how you're importing/using it in your page component on the Sanity community Discord where folks can help debug further with more context.

Are you using a .then method on the client when fetching the data.
client.fetch().then()?
Can you post it's use here?
Hi,
user S
Hi
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"]`)
You are importing the client right? Can't see the top
Also I would put the fetch methods in a getStaticProps method and pass into the component as props.
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.
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.
Then the issue isn't in the fetch function. There is another promise executing somewhere.
I'm really not sure where
It looks like you’re chaining a
then
somewhere to a fetch somewhere?
Hi RD, I have just fixed this and honestly I don't know how. I just rebuilt the project

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?