Error: "Cannot use import statement outside a module" on graphql deploy

17 replies
Last updated: Jan 28, 2026
I’m experiencing an error when trying to deploy
sanity graphql deploy
and getting this error point towards a node_module
import ColorPicker from '../components/input';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Does anyone know what’s causing this issue. I have been fine with this studio until the moment.
AI Update

This "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 Root Cause

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
  ])
})

The Solution

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
  ])
})

Additional Troubleshooting Steps

1. Check your Node.js version

If you're using Sanity Studio v4, you need Node.js 20 or higher:

node --version

2. Clear and reinstall dependencies

Sometimes the issue is with a corrupted package:

rm -rf node_modules package-lock.json
npm install

3. Look for color picker plugins

Check your package.json for packages like:

  • sanity-plugin-color-input
  • @sanity/color-input
  • Any custom input components

Try updating them:

npm update

4. 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!

Show original thread
17 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.

Was this answer helpful?