Error: spawn cmd.exe ENOENT when installing Sanity in existing NextJS project
The error you're encountering (spawn cmd.exe ENOENT) is a Windows-specific issue related to how Node.js tries to spawn child processes, not actually a Sanity-specific problem. The ENOENT error means "no such file or directory" - essentially, npm can't find or execute cmd.exe properly.
Here are several solutions to try:
1. Check your ComSpec environment variable
The most common cause is a missing or incorrect ComSpec environment variable. Open a Command Prompt or PowerShell as Administrator and run:
echo %ComSpec%It should return C:\Windows\System32\cmd.exe. If it doesn't exist or is incorrect, set it:
setx ComSpec "C:\Windows\System32\cmd.exe"Then restart your terminal and VSCode completely.
2. Use an alternative installation method
Instead of using npm create sanity@latest, try installing the Sanity CLI globally first, then running init:
npm install -g @sanity/cli
cd your-nextjs-project
sanity initThis approach gives you more control and often avoids the spawning issues with npm create. The sanity init command will walk you through an interactive setup process for adding Sanity to your existing Next.js project.
3. Run from Command Prompt instead of VSCode terminal
Sometimes VSCode's integrated terminal has issues with environment variables. Try running the same command from a native Windows Command Prompt or PowerShell (not inside VSCode).
4. Manual installation
If the automated setup continues to fail, you can manually install Sanity into your Next.js project:
npm install sanity @sanity/vision styled-components
npm install --save-dev @sanity/typesThen create your Sanity Studio files manually following the Next.js integration documentation.
5. Check your PATH
Ensure C:\Windows\System32 is in your system PATH. Sometimes security software or system configurations can interfere with this.
6. Try a different package manager
If you have pnpm or yarn installed, try using those instead:
pnpm create sanity@latest
# or
yarn create sanityThe spawn cmd.exe ENOENT error is frustrating but usually fixable with the ComSpec fix. After trying these solutions, make sure to completely close and reopen your terminal/VSCode to ensure environment variables are refreshed. The issue is almost always environment-related on Windows rather than a problem with Sanity itself.
Show original thread2 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.