Import error: 'retry' not exported from 'get-it/middleware' in Sanity client
This is a common dependency compatibility issue between @sanity/client and its underlying get-it package when using older versions of Next.js. Based on a resolved case in the Sanity community, the solution involves upgrading your Next.js version.
What's Causing This Error
The error 'retry' is not exported from 'get-it/middleware' happens because older Next.js versions (particularly Next.js 13) have fallen out of compatibility with current Sanity packages. The get-it package that powers @sanity/client has evolved its module exports in ways that older bundlers don't handle correctly.
The Solution: Upgrade to Next.js 14+
Here's the step-by-step fix:
1. Clean Your Project
Remove existing dependencies to start fresh:
rm -rf node_modules package-lock.json2. Update package.json
Upgrade these key packages to their latest versions:
{
"dependencies": {
"next": "latest",
"next-sanity": "latest",
"@sanity/client": "latest"
}
}3. Reinstall Dependencies
If you have peer dependency conflicts (common with styled-components):
npm install --legacy-peer-deps4. Verify Everything Works
Test both development and production builds:
npm run dev
npm run buildQuick Workarounds (Temporary)
If you can't upgrade immediately, try these:
Force Vite to re-bundle:
npm run dev -- --forceOr clear cache completely:
rm -rf node_modules
npm install --legacy-peer-depsAdditional Troubleshooting
- If you see
Invalid Version: 6.1during npm install, check for malformed version strings in your dependencies - Ensure you're using Node.js 18+ (required for modern Next.js and Sanity versions)
- The error occurs in
index.browser.jsbecause it's happening during browser bundle compilation - If using
npm-force-resolutions, remove it from your package.json—modern npm versions handle resolutions differently
The upgrade to Next.js 14 or later is the most reliable long-term solution. Sanity's current packages are built and tested against modern Next.js versions, ensuring proper bundling and module resolution.
Show original thread12 replies
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.