Issue with deploying GraphQL endpoint for Sanity Studio
Good news that you found a solution! For anyone else encountering this Error [ERR_REQUIRE_ESM]: require() of ES Module string-width from cliui not supported error when running sanity graphql deploy, this is typically a Node.js version compatibility issue with the Sanity CLI and its dependencies.
The error occurs because some dependencies in the Sanity CLI toolchain have moved to ES modules, which can cause conflicts with certain Node.js versions. Here are the solutions that typically work:
Primary Solution:
- Delete your
node_modulesfolder and lock file (package-lock.json,yarn.lock, orpnpm-lock.yaml) - Upgrade to a more recent Node.js version - Sanity Studio v4 requires Node.js 20+, and Node 21+ is recommended for avoiding these CLI issues
- Reinstall your dependencies with
npm install(or your package manager of choice) - Try
sanity graphql deployagain
Important Context:
As mentioned in the GraphQL deployment documentation, the GraphQL endpoint is not automatically deployed when you deploy your studio. You need to run sanity graphql deploy manually, and you'll need to re-deploy it every time you update your Sanity schema (not just content changes).
Additional Notes:
- Make sure you're running the command from your Sanity project directory where your schema is defined
- You can use
--dry-runto validate your API before deploying - The GraphQL playground is publicly accessible by default; use
--no-playgroundif you want to disable it
If upgrading Node.js doesn't resolve the issue, double-check that your package.json has "type": "module" if you're using ES modules throughout your project, or ensure consistency in how you're importing/requiring modules across your configuration files.
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.