Error: spawn cmd ENOENT" during sanity init command in React project
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 initOn 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:
Run your terminal as Administrator - Right-click your command prompt/PowerShell and select "Run as administrator", then try again
Check your PATH environment variable:
- Make sure
C:\Windows\System32is in your PATH - Open System Properties → Environment Variables → System Variables → Path
- Verify that path exists in the list
- Make sure
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@latestThis 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 --typescriptThe 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 thread3 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.