nodejs/node · error · GypError
%s: error: no build_file
Error message
%s: error: no build_file
What it means
gyp main raises GypError('%s: error: no build_file') after both the command line and FindBuildFiles() come up empty. Gyp needs at least one .gyp/.gypi build file as input to generate project files; with none supplied and none auto-discovered, it cannot proceed. The message is formatted with the program name (my_name) so the usage string reads naturally.
Source
Thrown at tools/gyp/pylib/gyp/__init__.py:567
for mode in options.debug:
gyp.debug[mode] = 1
# Do an extra check to avoid work when we're not debugging.
if DEBUG_GENERAL in gyp.debug:
DebugOutput(DEBUG_GENERAL, "running with these options:")
for option, value in sorted(options.__dict__.items()):
if option[0] == "_":
continue
if isinstance(value, str):
DebugOutput(DEBUG_GENERAL, " %s: '%s'", option, value)
else:
DebugOutput(DEBUG_GENERAL, " %s: %s", option, value)
if not build_files:
build_files = FindBuildFiles()
if not build_files:
raise GypError((usage + "\n\n%s: error: no build_file") % (my_name, my_name))
# TODO(mark): Chromium-specific hack!
# For Chromium, the gyp "depth" variable should always be a relative path
# to Chromium's top-level "src" directory. If no depth variable was set
# on the command line, try to find a "src" directory by looking at the
# absolute path to each build file's directory. The first "src" component
# found will be treated as though it were the path used for --depth.
if not options.depth:
for build_file in build_files:
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in range(components_len - 1, -1, -1):
if build_file_dir_components[index] == "src":
options.depth = os.path.sep.join(build_file_dir_components)
break
del build_file_dir_components[index]
View on GitHub (pinned to 1b2de5e052)
Solutions
- Pass the path to a .gyp file explicitly: `gyp path/to/project.gyp`.
- Run gyp from the directory containing the .gyp file so FindBuildFiles can auto-discover it.
- Check the file extension is .gyp/.gypi and not mangled by VFS case sensitivity.
Example fix
# before python gyp # after python gyp build/all.gyp
Defensive patterns
Strategy: validation
Validate before calling
import os, sys
args = sys.argv[1:]
build_files = [a for a in args if a.endswith(('.gyp',))]
if not build_files and not glob.glob('*.gyp'):
raise SystemExit('No .gyp build file found. Pass one explicitly, e.g. gyp project.gyp') Type guard
def has_build_file(args) -> bool:
import os
return any(a.endswith('.gyp') for a in args) or bool(glob.glob('*.gyp')) Try / catch
try:
gyp_main(args)
except GypError as e:
if 'no build_file' in str(e):
args.append('build/all.gyp') # then retry with an explicit file
raise Prevention
- Always pass the .gyp file path explicitly on the gyp command line.
- Run gyp from the directory that actually contains the .gyp file.
- In wrappers, assert a build file exists before delegating to gyp.
When it happens
Trigger: Running `gyp` with no positional arguments in a directory with no *.gyp files; passing only flags (-D, --depth) but no build file; FindBuildFiles globs a pattern that matches nothing.
Common situations: Wrong cwd (running gyp from repo root when the .gyp lives in a subdirectory); typo'd build file name that the shell swallowed; CI step that forgot to cd into the project dir.
Related errors
- Could not automatically locate src directory. This isa temp
- Need one argument which is the .gypi file to read.
- Unknown positional argument: ${extra}
- `${baseKey}` is not a valid npm option
- The `${baseKey}` option is deprecated, and cannot be set in
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/f0c1f4a076568471.
Report an issue: GitHub.