nodejs/node · error · Exception

ninja not found in PATH

Error message

ninja not found in PATH

What it means

Raised as an Exception by GenerateCompileDBWithNinja when shutil.which('ninja') returns None, meaning the ninja executable is not on PATH. This function shells out to `ninja -t compdb` to produce a compile_commands.json, so without the binary it cannot proceed.

Source

Thrown at tools/gyp/pylib/gyp/generator/ninja.py:2897

            os.path.join(toplevel_build, "compile_commands.json")
        )
        compile_db_file.write(json.dumps(compile_db, indent=2))
        compile_db_file.close()


def GenerateCompileDBWithNinja(path, targets=["all"]):
    """Generates a compile database using ninja.

    Args:
        path: The build directory to generate a compile database for.
        targets: Additional targets to pass to ninja.

    Returns:
        List of the contents of the compile database.
    """
    ninja_path = shutil.which("ninja")
    if ninja_path is None:
        raise Exception("ninja not found in PATH")
    json_compile_db = subprocess.check_output(
        [ninja_path, "-C", path]
        + targets
        + ["-t", "compdb", "cc", "cxx", "objc", "objcxx"]
    )
    return json.loads(json_compile_db)


def PerformBuild(data, configurations, params):
    options = params["options"]
    for config in configurations:
        builddir = os.path.join(options.toplevel_dir, "out", config)
        arguments = ["ninja", "-C", builddir]
        print(f"Building [{config}]: {arguments}")
        subprocess.check_call(arguments)


def CallGenerateOutputForConfig(arglist):

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Install ninja (e.g. `pip install ninja`, `apt install ninja-build`, or download the official release) and ensure the binary is named `ninja` on PATH.
  2. Verify with `which ninja` / `ninja --version` before invoking compile DB generation.
  3. On CI, add a ninja install step to the image or pipeline.

Example fix

# before — ninja missing
# install it
pip install ninja
# or
apt-get install -y ninja-build
# verify
ninja --version
Defensive patterns

Strategy: validation

Validate before calling

import shutil
if shutil.which('ninja') is None:
    raise EnvironmentError('ninja not found in PATH; install it')

Type guard

import shutil
def ninja_available() -> bool:
    return shutil.which('ninja') is not None

Prevention

When it happens

Trigger: Calling GenerateCompileDBWithNinja (e.g. via gyp --format=ninja compile-commands generation) in an environment where the ninja binary is not installed or not on PATH. shutil.which returns None at ninja.py:2896.

Common situations: Missing ninja install; PATH not updated after installing ninja; running in a container/CI image that lacks ninja; using a different build tool name (ninja-build) without a symlink.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/4d88feac303bb098. Report an issue: GitHub.