Troubleshooting a `sanity graphql deploy` error with a CLI upgrade/downgrade.

16 replies
Last updated: Jun 10, 2023
Trying to run a
sanity graphql deploy
but hitting this error…
ReferenceError: URL is not defined
…the stack trace isn’t helpful. Is there a verbose mode?
I don’t have an errant “URL” meant as a string. I’ve searched.

I’ve been sitting on a schema update (adding a field to a doc) for a while, so no recent relevant changes to look through.
AI Update

Based on the error you're encountering, this is almost certainly a Node.js version issue. The ReferenceError: URL is not defined error typically occurs when running Sanity CLI commands on older versions of Node.js.

The Solution

You need to upgrade to Node.js 18 or higher (preferably Node.js 20+). The URL global object wasn't available in older Node versions, which is why you're seeing this error during sanity graphql deploy.

According to Sanity's Studio v4 documentation, the current Sanity CLI requires Node.js 20+, though Node 18 should work with older versions of the CLI. The migration guide confirms this requirement was updated from Node.js 18 to Node.js 20+.

Check your Node version:

node --version

If you're below v18, upgrade Node.js and try again.

Enabling Verbose Mode

For future debugging, you can enable verbose logging in the Sanity CLI using the DEBUG environment variable:

DEBUG=sanity:* sanity graphql deploy

Or for even more detailed output:

DEBUG=* sanity graphql deploy

This will show you much more detailed stack traces and help identify where errors are originating.

Why This Happens

The error message isn't helpful because the stack trace is coming from internal code that expects the URL global to exist. Since it doesn't exist in older Node versions, you get a cryptic error rather than a clear "please upgrade Node" message. Your schema changes are likely fine—the CLI just can't process them on the older runtime.

After upgrading Node, your sanity graphql deploy command should work normally and deploy your schema updates (including that field you've been sitting on).

What version of the CLI are you running?
I recently upgraded my cli to
3.10.1
while attempting an upgrade. That wen’t pretty badly, so I’m still using Sanity
2.30.1
…so perhaps I need to downgrade the cli.
🤔 Are you in a V2 or V3 Studio?
V2 still, the upgrade was no bueno.
I was hoping I could keep the fresh cli. No biggie.
Can you try upgrading to something like 2.35?
I could try.
sanity upgrade base@2.35
?
Ah, just the CLI
npm upgrade @sanity/cli@2.35
I believe
If it’s globally installed you’ll need to
-g
flag
I installed the new one globally and had the old one in the repo 😵‍💫
It ends up as
2.10.5
but it works!
Much appreciated.
Glad you got it working!
Is there any pro-services available to get upgraded to Sanity 3?
I made it part-way through the process, but didn’t feel confident about the config change-over… and still had a handful of plugins to get back in (after stripping it down to get it running at all).

Not a huge project, but a specialist would probably do it 5x faster than myself.

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?