Error with Promise.prototype.then in client.js causing frustration, seeking help.
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 dev4. 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/clientpackage 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.
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.