nodejs/node · error · Exception
Need one argument which is the .gypi file to read.
Error message
Need one argument which is the .gypi file to read.
What it means
Raised by main() in gypi_to_gn.py when the parsed command-line positional arguments are not exactly one. The script expects a single positional argument: the path to the .gypi file to convert. Both zero arguments and two-or-more arguments trip this guard, which runs after OptionParser has consumed the -r/--replace options.
Source
Thrown at tools/gypi_to_gn.py:302
def DeduplicateLists(values):
"""Recursively remove duplicate values in lists."""
if isinstance(values, list):
return sorted(list(set(values)))
if isinstance(values, dict):
for key in values:
values[key] = DeduplicateLists(values[key])
return values
def main():
parser = OptionParser()
parser.add_option("-r", "--replace", action="append",
help="Replaces substrings. If passed a=b, replaces all substrs a with b.")
(options, args) = parser.parse_args()
if len(args) != 1:
raise Exception("Need one argument which is the .gypi file to read.")
data = LoadPythonDictionary(args[0])
if options.replace:
# Do replacements for all specified patterns.
for replace in options.replace:
split = replace.split('=')
# Allow "foo=" to replace with nothing.
if len(split) == 1:
split.append('')
assert len(split) == 2, "Replacement must be of the form 'key=value'."
data = ReplaceSubstrings(data, split[0], split[1])
gn_dict = {}
for key in data:
gn_key = key.replace('-', '_')
# Sometimes .gypi files use the GYP syntax with percents at the end of the
# variable name (to indicate not to overwrite a previously-defined value):
# 'foo%': 'bar',View on GitHub (pinned to 1b2de5e052)
Solutions
- Invoke with exactly one positional path: `python tools/gypi_to_gn.py path/to/file.gypi`.
- Put any -r/--replace options before or after the single file, never in place of it.
- Loop over multiple files in a shell loop instead of passing them all at once.
Example fix
# before python tools/gypi_to_gn.py a.gypi b.gypi # after python tools/gypi_to_gn.py a.gypi python tools/gypi_to_gn.py b.gypi
Defensive patterns
Strategy: validation
Validate before calling
if len(args) != 1:
raise SystemExit('usage: gypi_to_gn.py [-r a=b] <file.gypi>') Prevention
- Wrap the script in a shell helper that enforces the single-argument contract.
- Document the exact invocation in your build README.
- Loop over multiple files externally; never pass more than one to a single invocation.
When it happens
Trigger: Running `python gypi_to_gn.py` with no positional file; running it with two or more positional files (`gypi_to_gn.py a.gypi b.gypi`); accidentally passing flags after the file such that OptionParser swallows the file as an option value and leaves args empty.
Common situations: Copy-pasting an invocation from docs that omitted the filename; batching several .gypi files in one call (unsupported); a wrapper script that conditionally appends the filename and skipped it on a given branch.
Related errors
- %s: error: no build_file
- Unknown positional argument: ${extra}
- Could not automatically locate src directory. This isa temp
- Invalid config specified via --build: %s
- Not enough arguments
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/2e9338918fbedf78.
Report an issue: GitHub.