#3355·node-gyp

gyp: 'Undefined variable android_ndk_path' when building native modules on Android (Termux) without NDK

Author: lesliechowshCreated Aug 13, 2026Updated Aug 14, 2026

Describe the bug

Building any native module with node-gyp on Android (Termux) fails with an unhelpful gyp error, even though a working toolchain (clang) is installed:

gyp: Undefined variable android_ndk_path in binding.gyp while trying to load binding.gyp

Environment: Termux on Android 15 (aarch64), Node v26.4.0, npm 12.0.2, clang 21, no NDK (Android NDK is not practical to install on Termux; the system provides its own bionic toolchain).

Root cause chain

  1. Termux's python3 reports sys.platform == "android", so gyp selects the android flavor.
  2. node-gyp does not use the headers shipped with the Node package (/usr/include/node/common.gypi, which Termux's packaging already patches for this exact issue); instead it downloads the official Node headers from nodejs.org into ~/.cache/node-gyp/<version>/.
  3. The official common.gypi has an OS == "android" branch that references <(android_ndk_path)/sources/android/cpufeatures. On a plain Android system with no NDK, android_ndk_path is undefined and gyp aborts with the message above — it reads as an internal gyp bug rather than a missing-NDK situation.

Expected behavior

  • Either node-gyp should prefer locally installed Node headers when present (Termux's /usr/include/node is a valid, already-patched header set), or
  • on Android without an NDK, emit an actionable error (e.g. "building native modules on Android requires the Android NDK, or use the system toolchain via --nodedir=/usr/include/node") instead of Undefined variable android_ndk_path.

Workaround (used successfully)

Patch ~/.cache/node-gyp/26.4.0/include/node/common.gypi: in the OS == "android" branch, replace -I<(android_ndk_path)/sources/android/cpufeatures with the system include dir. After that, node-pty and other native modules compile and link fine against the Termux bionic toolchain.

This affects every Termux user who builds native npm modules (node-pty, sharp, koffi, etc.).