spawn undefined\System32\WindowsPowerShell" error during Sanity login

8 replies
Last updated: Feb 28, 2023
Hello. Am trying to start a new sanity project using npm create sanity@latest . It installs the node packages. Then gets to the login prompts for different options(Google, Github, Email). I select any of them, but the terminal returns a wild error! Here is what it returns :? Login type Google
Opening browser at
https://api.sanity.io/v1/auth/login/google?type=listen&uuid=dfe6ead8885119fbdcfb100be38c997f&source=cli&label=DESKTOP-L0OHL9K+%2F+win32
- Waiting for browser login to complete... Press Ctrl + C to cancelnode
:events:491 throw er; // Unhandled 'error' event
^

Error: spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT
at ChildProcess._handle.onexit (node
:internal/child_process:283:19) at onErrorNT (node
:internal/child_process:476:16) at process.processTicksAndRejections (node
:internal/process/task_queues:82:21)Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node
:internal/child_process:289:12) at onErrorNT (node
:internal/child_process:476:16) at process.processTicksAndRejections (node
:internal/process/task_queues:82:21) { errno: -4058,
code: 'ENOENT',
syscall: 'spawn undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
path: 'undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
spawnargs: [
'-NoProfile',
'-NonInteractive',
'–ExecutionPolicy',
'Bypass',
'-EncodedCommand',
'UwB0AGEAcgB0ACAAIgBoAHQAdABwAHMAOgAvAC8AYQBwAGkALgBzAGEAbgBpAHQAeQAuAGkAbwAvAHYAMQAvAGEAdQB0AGgALwBsAG8AZwBpAG4ALwBnAG8AbwBnAGwAZQA/AHQAeQBwAGUAPQBsAGkAcwB0AGUAbgAmAHUAdQBpAGQAPQBkAGYAZQA2AGUAYQBkADgAOAA4ADUAMQAxADkAZgBiAGQAYwBmAGIAMQAwADAAYgBlADMAOABjADkAOQA3AGYAJgBzAG8AdQByAGMAZQA9AGMAbABpACYAbABhAGIAZQBsAD0ARABFAFMASwBUAE8AUAAtAEwAMABPAEgATAA5AEsAKwAlADIARgArAHcAaQBuADMAMgAiAA=='
]
}

Node.js v18.12.1
AI Update

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:

  1. Open Command Prompt as Administrator
  2. Run: setx SystemRoot C:\Windows /M
  3. Close and reopen your terminal
  4. Try npm create sanity@latest again

Solution 2: Use the login URL manually

If the above doesn't work, you can manually authenticate:

  1. Run npm create sanity@latest again
  2. When it fails, copy the login URL from the error message (the https://api.sanity.io/v1/auth/login/google?... part)
  3. Manually paste it into your browser
  4. Complete the authentication there
  5. 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:

  1. Open System Properties → Advanced → Environment Variables
  2. Check that SystemRoot exists in System variables and is set to C:\Windows
  3. 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 thread
8 replies
Hi
user V
. Would you be able to give this a try, please? It looks like this is a reported bug in a third-party dependency that impacts Windows PowerShell users. Until this is resolved, a confirmed workaround is to login using
sanity login --no-open
, which will provide you with a link you can follow to authenticate but not attempt to open the browser for you. This should provide enough of a delay to circumvent the issue.
I have this same problem, I'm trying to follow this tutorial on YouTube: https://www.youtube.com/watch?v=CcBHZ0t2Qwc
The workaround you have mentioned doesn't seem to work (or maybe I'm just doing it wrong).

I reinstalled node and npm, too, which was something mentioned in your troubleshooting guide.
Hi, had the same issue, use gitbash for your terminal, will fix that problem right away
Tried that fix , didn't work. Any other suggesstion?
user R
user R
The workaround would be to log in using
sanity login --no-open
, follow the link, and then return to the terminal. If that’s what you’ve tried and are still having an issue, please start a thread and post the error you’re seeing. Thanks!
This worked like a charm👍 ❤️ ...thanks..I have my sanity studio up and running 🏃‍♂️
Great! Thanks for following up to let us know. In a future version (not yet sure when), we’ll be implementing a workaround, since I don’t believe the third-party author plans to fix it on their end. That means this approach should be fairly temporary (hopefully less than a week).
Enjoy building!
Ere is how things have been all along, and the result after the using a solution above

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?