nodejs/node · error · Exception
Environment variable "%s" required to be set to valid path
Error message
Environment variable "%s" required to be set to valid path
What it means
After parsing the 'set' output into an env dict, _ExtractImportantEnvironment requires SYSTEMROOT, TEMP, and TMP to be present. These are needed to spawn compile/link processes correctly. If any is missing (the setup script's environment did not define them), gyp raises rather than emit a broken environment block.
Source
Thrown at tools/gyp/pylib/gyp/msvs_emulation.py:1133
# This occasionally happens and leads to misleading SYSTEMROOT error messages
# if not caught here.
if output_of_set.count("=") == 0:
raise Exception("Invalid output_of_set. Value is:\n%s" % output_of_set)
for line in output_of_set.splitlines():
for envvar in envvars_to_save:
if re.match(envvar + "=", line.lower()):
var, setting = line.split("=", 1)
if envvar == "path":
# Our own rules (for running gyp-win-tool) and other actions in
# Chromium rely on python being in the path. Add the path to this
# python here so that if it's not in the path when ninja is run
# later, python will still be found.
setting = os.path.dirname(sys.executable) + os.pathsep + setting
env[var.upper()] = setting
break
for required in ("SYSTEMROOT", "TEMP", "TMP"):
if required not in env:
raise Exception(
'Environment variable "%s" required to be set to valid path' % required
)
return env
def _FormatAsEnvironmentBlock(envvar_dict):
"""Format as an 'environment block' directly suitable for CreateProcess.
Briefly this is a list of key=value\0, terminated by an additional \0. See
CreateProcess documentation for more details."""
block = ""
nul = "\0"
for key, value in envvar_dict.items():
block += key + "=" + value + nul
block += nul
return block
def _ExtractCLPath(output_of_where):View on GitHub (pinned to 1b2de5e052)
Solutions
- In the shell where gyp runs, confirm the missing variable is set: echo %SYSTEMROOT% / %TEMP% / %TMP%.
- Set any missing variable (e.g. set SYSTEMROOT=C:\Windows) before invoking gyp/ninja.
- If using a container, bake these variables into the image.
- Verify the VS setup script isn't clearing them.
Example fix
// before: shell lacks SYSTEMROOT // after C:\> set SYSTEMROOT=C:\Windows C:\> set TEMP=C:\Users\me\AppData\Local\Temp C:\> set TMP=C:\Users\me\AppData\Local\Temp C:\> gyp --depth=. my.gyp
Defensive patterns
Strategy: validation
Validate before calling
import os
for required in ('SYSTEMROOT', 'TEMP', 'TMP'):
if not os.environ.get(required):
raise EnvironmentError(f'{required} must be set before running gyp/ninja on Windows') Type guard
def windows_env_complete() -> bool:
import os
return all(os.environ.get(v) for v in ('SYSTEMROOT', 'TEMP', 'TMP')) Prevention
- In CI containers, explicitly set SYSTEMROOT, TEMP, TMP.
- Verify the VS developer command prompt sets all three before invoking gyp.
- Log the parsed env block once during setup to catch regressions.
When it happens
Trigger: The parsed environment block lacks one of SYSTEMROOT, TEMP, or TMP — typically because the 'set' output did not contain a matching line (case-insensitive regex match on 'var=').
Common situations: A stripped-down or containerized Windows environment where these variables are not set; a CI image that cleared TEMP/TMP; a VS setup script that overwrote or omitted them; the same root cause as the Invalid output_of_set error (bad set output) but with '=' lines that simply lacked these keys.
Related errors
- %s is missing - make sure VC++ tools are installed.
- %s requires any SDK of %s version, but none were found
- Could not locate Visual Studio installation.
- Appending "%s" to a non-list setting "%s" for tool "%s" is n
- Invalid MSVS guid: "%s". Must match regex: "%s".
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/8ecd1ef8c9b5bc20.
Report an issue: GitHub.