spawn undefined\System32\WindowsPowerShell" error during Sanity login
This is a Windows-specific environment variable issue where the Sanity CLI can't find PowerShell because the SystemRoot environment variable is undefined or missing. The error spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT shows that it's trying to construct the path to PowerShell but getting "undefined" instead of C:\Windows.
Here are the solutions to fix this:
Solution 1: Set the SystemRoot environment variable
The SystemRoot environment variable is missing or not accessible. You need to set it:
- Open Command Prompt as Administrator
- Run:
setx SystemRoot C:\Windows /M - Close and reopen your terminal
- Try
npm create sanity@latestagain
Solution 2: Use the login URL manually
If the above doesn't work, you can manually authenticate:
- Run
npm create sanity@latestagain - When it fails, copy the login URL from the error message (the
https://api.sanity.io/v1/auth/login/google?...part) - Manually paste it into your browser
- Complete the authentication there
- The CLI should detect the successful login
Solution 3: Try a different terminal
Sometimes this is terminal-specific. Try using:
- Windows Command Prompt (cmd.exe) instead of PowerShell
- Git Bash if you have it installed
- WSL (Windows Subsystem for Linux) - as mentioned in this Sanity answer, this has been reported to work when Windows terminals fail
Solution 4: Update Node.js
You're running Node.js v18.12.1. Try updating to a more recent Node.js version (Node 20+ is now recommended for Sanity Studio v4). Sometimes environment variable handling is improved in newer Node versions.
Solution 5: Check environment variables manually
Verify your environment variables are intact:
- Open System Properties → Advanced → Environment Variables
- Check that
SystemRootexists in System variables and is set toC:\Windows - If it's missing, add it manually through the GUI
The root cause is that the Sanity CLI uses the open package to launch your browser for authentication, which on Windows tries to use PowerShell, but it can't construct the correct path without the SystemRoot variable. Solution 1 is usually the quickest fix!
Show original thread8 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.