Error: spawn cmd ENOENT" during sanity init command in React project

3 replies
Last updated: Oct 18, 2022
Hello everyone, I'm trying to add sanity to my react project and whenever I try to run the "sanity init" command, I'm getting an error message. This is the message: You're setting up a Sanity.io project!We'll make sure you're logged in with
Sanity.io .Then, we'll install a Sanity Studio for your project.

Press ctrl + C at any time to quit.

We can't find any auth credentials in your Sanity config
- log in or create a new account


Opening browser at
https://api.sanity.io/v1/auth/login/sanity?type=listen&uuid=bbbcd622884f8f3a9ac7760981b8e379&source=cli
⠋ Waiting for browser login to complete... Press Ctrl + C to cancelnode
:events:491 throw er; // Unhandled 'error' event
^

Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (node
:internal/child_process:285:19) at onErrorNT (node
:internal/child_process:485:16) at processTicksAndRejections (node
:internal/process/task_queues:83:21)Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node
:internal/child_process:291:12) at onErrorNT (node
:internal/child_process:485:16) at processTicksAndRejections (node
:internal/process/task_queues:83:21) { errno: -4058,
code: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs: [
'/c',
'start',
'""',
'/b',
'
https://api.sanity.io/v1/auth/login/sanity?type=listen^&uuid=bbbcd622884f8f3a9ac7760981b8e379^&source=cli ' ]
} I'm stuck, Help.
AI Update

The error you're encountering (Error: spawn cmd ENOENT) is a Windows-specific issue where the Sanity CLI is trying to automatically open your browser for login but can't find the cmd command. This typically happens due to PATH environment variable issues or permission problems on Windows.

Here are several solutions to get you past this:

Quick Fix: Manual Login with the Browser URL

When you see the error, the CLI has already generated a login URL. Copy the URL that appears in the error message (the https://api.sanity.io/v1/auth/login/sanity?... part) and paste it directly into your browser. Complete the login there, and the CLI should detect it and continue with the initialization.

Use Environment Variable for Authentication

If you need to authenticate without the browser flow, you can use an authentication token with environment variables. First, get a token from your Sanity account settings, then use it like this:

SANITY_AUTH_TOKEN=<your-token> sanity init

On Windows Command Prompt:

set SANITY_AUTH_TOKEN=<your-token>
sanity init

On Windows PowerShell:

$env:SANITY_AUTH_TOKEN="<your-token>"
sanity init

This approach is documented in the Sanity CLI documentation for running commands with authentication.

Fix the Root Cause (Windows PATH)

The ENOENT error means Node.js can't find the cmd executable. Try these approaches:

  1. Run your terminal as Administrator - Right-click your command prompt/PowerShell and select "Run as administrator", then try again

  2. Check your PATH environment variable:

    • Make sure C:\Windows\System32 is in your PATH
    • Open System Properties → Environment Variables → System Variables → Path
    • Verify that path exists in the list
  3. Use a different terminal:

    • Try Git Bash instead of Command Prompt
    • Or use PowerShell instead of CMD
    • VS Code's integrated terminal often works better for these scenarios

Modern Alternative: Create Project via Web

If you continue having issues, you can use the modern create command:

npm create sanity@latest

This newer approach (npm create sanity@latest) is generally more reliable than sanity init and handles authentication more gracefully across different platforms. You can also specify options directly:

npm create sanity@latest -- --dataset production --template clean --typescript

The manual browser URL approach is usually the fastest workaround for this specific Windows authentication issue, while switching to npm create sanity@latest gives you a more modern and reliable setup experience overall.

Show original thread
3 replies
As a Windows user who runs into command line issues on occasion, I am wondering if the problem might be resolved by one of these solutions, which all seem to relate to environment variables on the OS: https://stackoverflow.com/questions/57054403/problem-with-npm-start-error-spawn-cmd-enoent
Thank you so much.. You pointed me in the right direction, the issue is now gone... I was missing a path pointing  to System32 in the environment variables.
No problem! It's not easy to notice and sometimes a single letter off of what it says it wants keeps everything from working.

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?