
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis is a classic Next.js + Sanity configuration issue that's been reported before. The error you're seeing happens because Next.js needs to transpile certain Sanity packages (specifically @sanity/ui) that are distributed as ESM (ES Module) files.
Based on the community discussion around this exact issue, there are two solutions:
Add transpilePackages to your next.config.js or next.config.mjs:
/** @type {import('next').NextConfig} */
const config = {
transpilePackages: ['@sanity/ui', '@sanity/icons'],
// ... rest of your config
}
module.exports = configOr if using next.config.mjs:
/** @type {import('next').NextConfig} */
const config = {
transpilePackages: ['@sanity/ui', '@sanity/icons'],
// ... rest of your config
}
export default configThis tells Next.js to transpile these specific packages during the build process, which resolves the "sourceType: module" error.
If you're using Yarn, you can add a resolution to your package.json:
"resolutions": {
"@sanity/ui": "1.0.5"
}Then delete your node_modules and yarn.lock, and run yarn install again. This was the workaround suggested when the issue first appeared with @sanity/ui@1.0.6.
You mentioned running Node 19.3.0 - this could be contributing to the issue. Node 19 is an odd-numbered release that's no longer maintained. I'd strongly recommend switching to:
Vercel's build environment may have different default configurations or webpack settings that handle ESM imports differently. The transpilePackages configuration ensures consistent behavior across all environments.
After making these changes, delete your .next folder and run yarn build again. The transpilePackages solution is the proper long-term fix, while the version pinning is just a temporary workaround.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store