{"record":{"id":"8ecd1ef8c9b5bc20","repo":"nodejs/node","slug":"environment-variable-s-required-to-be-set-to-va","errorCode":null,"errorMessage":"Environment variable \"%s\" required to be set to valid path","messagePattern":"Environment variable \"(.+?)\" required to be set to valid path","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/msvs_emulation.py","lineNumber":1133,"sourceCode":"    # This occasionally happens and leads to misleading SYSTEMROOT error messages\n    # if not caught here.\n    if output_of_set.count(\"=\") == 0:\n        raise Exception(\"Invalid output_of_set. Value is:\\n%s\" % output_of_set)\n    for line in output_of_set.splitlines():\n        for envvar in envvars_to_save:\n            if re.match(envvar + \"=\", line.lower()):\n                var, setting = line.split(\"=\", 1)\n                if envvar == \"path\":\n                    # Our own rules (for running gyp-win-tool) and other actions in\n                    # Chromium rely on python being in the path. Add the path to this\n                    # python here so that if it's not in the path when ninja is run\n                    # later, python will still be found.\n                    setting = os.path.dirname(sys.executable) + os.pathsep + setting\n                env[var.upper()] = setting\n                break\n    for required in (\"SYSTEMROOT\", \"TEMP\", \"TMP\"):\n        if required not in env:\n            raise Exception(\n                'Environment variable \"%s\" required to be set to valid path' % required\n            )\n    return env\n\n\ndef _FormatAsEnvironmentBlock(envvar_dict):\n    \"\"\"Format as an 'environment block' directly suitable for CreateProcess.\n    Briefly this is a list of key=value\\0, terminated by an additional \\0. See\n    CreateProcess documentation for more details.\"\"\"\n    block = \"\"\n    nul = \"\\0\"\n    for key, value in envvar_dict.items():\n        block += key + \"=\" + value + nul\n    block += nul\n    return block\n\n\ndef _ExtractCLPath(output_of_where):","sourceCodeStart":1115,"sourceCodeEnd":1151,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/msvs_emulation.py#L1115-L1151","documentation":"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.","triggerScenarios":"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=').","commonSituations":"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.","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."],"exampleFix":"// before: shell lacks SYSTEMROOT\n// after\nC:\\> set SYSTEMROOT=C:\\Windows\nC:\\> set TEMP=C:\\Users\\me\\AppData\\Local\\Temp\nC:\\> set TMP=C:\\Users\\me\\AppData\\Local\\Temp\nC:\\> gyp --depth=. my.gyp","handlingStrategy":"validation","validationCode":"import os\nfor required in ('SYSTEMROOT', 'TEMP', 'TMP'):\n    if not os.environ.get(required):\n        raise EnvironmentError(f'{required} must be set before running gyp/ninja on Windows')","typeGuard":"def windows_env_complete() -> bool:\n    import os\n    return all(os.environ.get(v) for v in ('SYSTEMROOT', 'TEMP', 'TMP'))","tryCatchPattern":null,"preventionTips":["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."],"tags":["gyp","msvs","environment","windows"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}