
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThis "Cannot use import statement outside a module" error during sanity graphql deploy is a classic Node.js module system conflict. The issue occurs when the GraphQL deploy process tries to load your schema (including all custom input components), and encounters ES module syntax (import/export) in a context expecting CommonJS.
Based on the Sanity documentation on this error, here's what's happening and how to fix it:
The error points to a ColorPicker component using ES module syntax. This typically happens when you have a schema type definition like:
export default {
// ... type definition
}But you're importing it using CommonJS require():
import createSchema from 'part:@sanity/base/schema-creator'
export default createSchema({
name: 'my-schema',
types: schemaTypes.concat([
require('./someTypeDef.js') // ← This is the problem
])
})Use ES module import statements instead of require():
import createSchema from 'part:@sanity/base/schema-creator'
import someTypeDef from './someTypeDef'
export default createSchema({
name: 'my-schema',
types: schemaTypes.concat([
someTypeDef // ← Much better
])
})1. Check your Node.js version
If you're using Sanity Studio v4, you need Node.js 20 or higher:
node --version2. Clear and reinstall dependencies
Sometimes the issue is with a corrupted package:
rm -rf node_modules package-lock.json
npm install3. Look for color picker plugins
Check your package.json for packages like:
sanity-plugin-color-input@sanity/color-inputTry updating them:
npm update4. Review your schema files
Search your schema files for any require() statements and replace them with proper import statements at the top of the file.
The GraphQL API deployment command needs to parse your entire schema, so any module system mismatches will cause this error. Once you've converted all your schema imports to use ES modules consistently, the deploy should work fine.
If the issue persists after these fixes, share your schema configuration and the specific file paths mentioned in the error for more targeted help!
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