nodejs/node · error · Exception
Unable to parse config file %s%s
Error message
Unable to parse config file %s%s
What it means
Thrown by the analyzer GYP generator's Config.Init when it opens the file pointed to by the config_path generator flag but json.load() raises a ValueError. This means the file exists and is readable, but its contents are not syntactically valid JSON. The exception chains the original parse error so the exact JSON syntax problem is visible.
Source
Thrown at tools/gyp/pylib/gyp/generator/analyzer.py:279
self.targets = set()
self.additional_compile_target_names = set()
self.test_target_names = set()
def Init(self, params):
"""Initializes Config. This is a separate method as it raises an exception
if there is a parse error."""
generator_flags = params.get("generator_flags", {})
config_path = generator_flags.get("config_path", None)
if not config_path:
return
try:
f = open(config_path)
config = json.load(f)
f.close()
except OSError:
raise Exception("Unable to open file " + config_path)
except ValueError as e:
raise Exception("Unable to parse config file " + config_path + str(e))
if not isinstance(config, dict):
raise Exception("config_path must be a JSON file containing a dictionary")
self.files = config.get("files", [])
self.additional_compile_target_names = set(
config.get("additional_compile_targets", [])
)
self.test_target_names = set(config.get("test_targets", []))
def _WasBuildFileModified(build_file, data, files, toplevel_dir):
"""Returns true if the build file |build_file| is either in |files| or
one of the files included by |build_file| is in |files|. |toplevel_dir| is
the root of the source tree."""
if _ToLocalPath(toplevel_dir, _ToGypPath(build_file)) in files:
if debug:
print("gyp file modified", build_file)
return True
View on GitHub (pinned to 1b2de5e052)
Solutions
- Validate the config file with a JSON linter (e.g. `python -m json.tool config.json`) to surface the exact syntax error and line.
- Ensure all keys are double-quoted, remove trailing commas, and remove any comments — strict JSON only.
- Regenerate the config file programmatically with json.dump() rather than hand-writing or string-formatting it.
- Check that the file was fully written (no truncation) and has the correct encoding (UTF-8, no BOM).
Example fix
// before (config.json)
{
files: ['a.cc'], // unquoted keys + trailing comma
}
// after
{
"files": ["a.cc"]
} Defensive patterns
Strategy: validation
Validate before calling
import json, sys
path = 'config.json'
try:
with open(path) as f:
json.load(f)
print('config JSON is valid')
except json.JSONDecodeError as e:
print(f'invalid JSON: {e}'); sys.exit(1)
except OSError as e:
print(f'cannot open: {e}'); sys.exit(1) Type guard
def is_valid_config_dict(obj) -> bool:
return isinstance(obj, dict) and 'files' in obj Try / catch
try:
config.Init(params)
except Exception as e:
if 'Unable to parse config file' in str(e):
report_config_error(config_path, e)
raise Prevention
- Validate the analyzer config with python -m json.tool before invoking gyp.
- Generate the config file with json.dump rather than hand-writing JSON.
- Run a pre-flight check in CI that parses every config_path file.
When it happens
Trigger: Running gyp with --format=analyzer and a --generator-flag=config_path=<file> where <file> contains malformed JSON (trailing comma, unquoted keys, single quotes, a comment, or a truncated file). json.load succeeds at open() but fails during parsing, landing in the `except ValueError` branch at analyzer.py:278.
Common situations: Hand-editing the analyzer config JSON and introducing a syntax error; generating the config file with a script that emits JS-style object literals (unquoted keys) or trailing commas; a truncated file from an interrupted write; copy-pasting from a Python dict repr instead of valid JSON.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to open file %s
- config_path must be a JSON file containing a dictionary
- Must specify files to analyze via config_path generator flag
- Failed to parse config file "%s": %s
- GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be set t
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/de5ea9c2996aaa08.
Report an issue: GitHub.