{"record":{"id":"4d88feac303bb098","repo":"nodejs/node","slug":"ninja-not-found-in-path","errorCode":null,"errorMessage":"ninja not found in PATH","messagePattern":"ninja not found in PATH","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/generator/ninja.py","lineNumber":2897,"sourceCode":"            os.path.join(toplevel_build, \"compile_commands.json\")\n        )\n        compile_db_file.write(json.dumps(compile_db, indent=2))\n        compile_db_file.close()\n\n\ndef GenerateCompileDBWithNinja(path, targets=[\"all\"]):\n    \"\"\"Generates a compile database using ninja.\n\n    Args:\n        path: The build directory to generate a compile database for.\n        targets: Additional targets to pass to ninja.\n\n    Returns:\n        List of the contents of the compile database.\n    \"\"\"\n    ninja_path = shutil.which(\"ninja\")\n    if ninja_path is None:\n        raise Exception(\"ninja not found in PATH\")\n    json_compile_db = subprocess.check_output(\n        [ninja_path, \"-C\", path]\n        + targets\n        + [\"-t\", \"compdb\", \"cc\", \"cxx\", \"objc\", \"objcxx\"]\n    )\n    return json.loads(json_compile_db)\n\n\ndef PerformBuild(data, configurations, params):\n    options = params[\"options\"]\n    for config in configurations:\n        builddir = os.path.join(options.toplevel_dir, \"out\", config)\n        arguments = [\"ninja\", \"-C\", builddir]\n        print(f\"Building [{config}]: {arguments}\")\n        subprocess.check_call(arguments)\n\n\ndef CallGenerateOutputForConfig(arglist):","sourceCodeStart":2879,"sourceCodeEnd":2915,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/generator/ninja.py#L2879-L2915","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Verify with `which ninja` / `ninja --version` before invoking compile DB generation.","On CI, add a ninja install step to the image or pipeline."],"exampleFix":"# before — ninja missing\n# install it\npip install ninja\n# or\napt-get install -y ninja-build\n# verify\nninja --version","handlingStrategy":"validation","validationCode":"import shutil\nif shutil.which('ninja') is None:\n    raise EnvironmentError('ninja not found in PATH; install it')","typeGuard":"import shutil\ndef ninja_available() -> bool:\n    return shutil.which('ninja') is not None","tryCatchPattern":null,"preventionTips":["Install ninja and verify with `ninja --version` before compile-DB generation.","Add a ninja install step to CI containers."],"tags":["gyp","ninja","environment","path","dependency-missing"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}