gyp: 'Undefined variable android_ndk_path' when building native modules on Android (Termux) without NDK
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- android, nodejs, python
調査の方向性
まず Termux で失敗を再現し、node-gyp のヘッダー選択をキャッシュされた common.gypi まで追跡します。特に OS == "android" ブランチと、そこから参照される android_ndk_path に注目してください。そのパスを、パッチが適用された /usr/include/node のヘッダーおよび --nodedir の回避策と比較します。Android で NDK がない場合に、未定義変数による誤解を招く失敗が発生しなくなり、選択したサポート対象のパスがテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- Termux's python3 reports
sys.platform == "android", so gyp selects theandroidflavor. - 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>/. - The official
common.gypihas anOS == "android"branch that references<(android_ndk_path)/sources/android/cpufeatures. On a plain Android system with no NDK,android_ndk_pathis 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/nodeis 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 ofUndefined 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.).
- 主要言語
- Python
- スター
- 10.7k
- フォーク
- 1.9k
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 5
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nodejs/node-gyp のほかの issue
-
dependencies github_actions
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
MSYS2
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
nodejs/node-gyp の issue をすべて見る
似ている issue
-
bug confirmed issue
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
open-webui/open-webui#30750 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 90/100