投稿:Termux / Android における Astro 7 のビルド互換性修正記録

公開日: 2026-10-27 10:16 更新日: 2026-10-27 10:17 1504文字 8 min read

投稿:Termux / Android における Astro 7 のビルド互換性修正記録Posts: Astro Blog Studio:静的ブログに純フロントエンドのオンライン編集バックエンドを提供Posts: Wallpaper Engine 壁紙おすすめ - 二次元ランダム壁紙投稿: Umami を通じて API 訪問者データを取得する投稿: N 匹の豚 ~ネットユーザーPythonでWindowsファイルのデフォルトアプリケーションを設定する方法投稿: ノート管理プラットフォームを開発しました投稿: H 漫画ウェブサイトスクレイピング実戦投稿: Pythonスクレイピング 汎用的な小説ダウンローダー投稿: 菜鸟教程ウェブサイトのチュートリアルをスクレイピングし、ローカルのMarkdownファイルに保存するPythonスクリプト投稿一覧: Hexo テーマ開発ノート投稿: Umami Cloudのデータをエクスポートして、自前で構築したUmamiにインポートする記事:Decap CMSをHexoのバックエンドとして使用してオンライン編集を実現する方法(親切なチュートリアル)投稿: ArtPlayer プレーヤーの簡単な使い方綺麗な二次元画像の共有Posts: 転載、なぜ私たちはいつも他人が自ら動いてくれるのを待ってしまうのか?投稿: Hexo Volantisテーマのサブタイトルをタイピング効果で表示する Hitokotoタイプライター効果の Hitokoto(html+css+js)网易云音乐プレイリストの曲をバッチダウンロード(python)投稿: Hexo Volantisテーマの音楽プレイヤーAplayerはダークモードに適応し、変化に追随できます投稿: このサイトのウォールペーパー
Astro 7 プロジェクトを Termux / Android(aarch64)上で pnpm build できるよう修正した全過程を記録する。Sätteri に Android 向けネイティブバインディングがない場合の WASI フォールバックと pnpm patch によるパッチ適用、さらに Pagefind に Android 向けビルドが存在しない場合に linux-arm64 の静的バイナリを再利用する互換ソリューションを網羅する。

AIモデル deepseek-flash による翻訳。

原文言語:Simplified Chinese、翻訳先言語:japanese、翻訳時間:2026-10-27 10:23

。

AI翻訳は参考に限り、内容の完全な正確性を保証できません。原文をご参照ください。

前言

本記事では、Astro 7 プロジェクトを Termux / Android 上で pnpm build がエラーになる状態から完全にビルドできる状態まで修正した実際の手順を記録します。

Astro 7 プロジェクト自体は @astrojs/markdown-remark の unified() を Markdown プロセッサーとして使用していますが、その設定スキーマはモジュールの読み込み段階で @astrojs/markdown-satteri をインポートします。Sätteri には Android ネイティブバインディングがないため、プロジェクトが unified() を使用していても、Sätteri のネイティブバインディングの読み込みが発生します。

テスト環境

コンポーネントバージョン
Android14 / aarch64
Node.js25.8.1
pnpm11.0.9
Astro7.4.2
Pagefind1.5.2
Sätteri0.10.5

1. Sätteri には Android ネイティブバインディングがない

現象

Cannot find native binding. npm has a bug related to optional dependencies...
cause: Error: Cannot find module '@bruits/satteri-android-arm64'

astro check は設定の読み込み段階で失敗し、コンテンツの処理はまだ開始されていません。

原因の特定

@astrojs/markdown-satteri は satteri に依存しています。satteri@0.10.5 の optionalDependencies は次のものだけです:

@bruits/satteri-linux-x64-gnu
@bruits/satteri-linux-arm64-gnu
@bruits/satteri-linux-x64-musl
@bruits/satteri-linux-arm64-musl
@bruits/satteri-darwin-x64
@bruits/satteri-darwin-arm64
@bruits/satteri-win32-x64-msvc
@bruits/satteri-win32-arm64-msvc
@bruits/satteri-wasm32-wasi

その中に android-arm64 は含まれていません。ただし、satteri のバインディングローダーには Android 分岐と WASI フォールバックが含まれています:

if (process.platform === 'android') {
  if (process.arch === 'arm64') {
    try { return require('./satteri_napi.android-arm64.node') } catch (e) { ... }
  }
}
...
if (!nativeBinding || forceWasi) {
  try {
    wasiBinding = require('@bruits/satteri-wasm32-wasi')
    nativeBinding = wasiBinding
  } catch (err) { ... }
}

したがって、Android ネイティブモジュールをコンパイルする必要はなく、WASI パッケージを直接使用すれば済みます。

修正

WASI フォールバックをインストールします:

pnpm add -D @bruits/satteri-wasm32-wasi@0.10.5

インストール後、satteri は WASI バインディングを見つけられますが、2 つ目のエラーが発生します:

Error: UVWASI_EACCES, uvwasi_init

原因は、WASI の初期化時に / を preopen として扱っていることです:

const __rootDir = __nodePath.parse(process.cwd()).root
const __wasi = new __nodeWASI({
  version: 'preview1',
  env: process.env,
  preopens: {
    [__rootDir]: __rootDir,
  }
})

Android ではルートディレクトリの事前オープンが許可されていないため、process.cwd() に変更します:

pnpm patch @bruits/satteri-wasm32-wasi@0.10.5

pnpm が出力した一時ディレクトリを編集します:

node_modules/.pnpm_patches/@bruits/satteri-wasm32-wasi@0.10.5/satteri_napi.wasi.cjs

-const __rootDir = __nodePath.parse(process.cwd()).root
+const __rootDir = process.cwd()

node_modules/.pnpm_patches/@bruits/satteri-wasm32-wasi@0.10.5/wasi-worker.mjs

-const __rootDir = parse(process.cwd()).root;
+const __rootDir = process.cwd();

パッチをコミットします:

pnpm patch-commit node_modules/.pnpm_patches/@bruits/satteri-wasm32-wasi@0.10.5

リポジトリには最終的に次が生成されます:

patches/@bruits__satteri-wasm32-wasi@0.10.5.patch

注意事項

pnpm patch-commit は Already up to date と表示することがありますが、インストール済みの node_modules 内は依然として古いファイルのままです。pnpm install --force で解決しようとせず、直接削除して再インストールしてください:

rm -rf node_modules
pnpm install --frozen-lockfile

Sätteri が読み込めることを確認します:

node -e "
const { createRequire } = require('module');
const r = createRequire(process.cwd() + '/node_modules/.pnpm/satteri@0.10.5/node_modules/satteri/index.js');
const m = r('satteri');
console.log('satteri OK', Object.keys(m).length);
"

satteri OK 34 が出力され、ExperimentalWarning: WASI is an experimental feature が 1 件付随しますが、正常な現象です。


2. Pagefind に Android ビルドがない(Pagefind を使用する場合)

現象

astro build は完了していますが、postbuild 段階で失敗します:

$ pagefind --site dist
Failed to install either of [pagefind_extended, pagefind].
Most likely the platform android-arm64 is not yet a supported architecture.

原因の特定

pagefind/lib/resolveBinary.js は process.platform に基づいてパッケージ名を直接組み立てています:

const cpu = process.env.npm_config_arch || os.arch();
const platform = process.platform === "win32" ? "windows" : process.platform;

for (const execname of execnames) {
  const executable = platform === "windows" ? `${execname}.exe` : execname;
  try {
    return require.resolve(`@pagefind/${platform}-${cpu}/bin/${executable}`);
  } catch (e) {}
}

@pagefind/android-arm64 は存在しません。

しかし、@pagefind/linux-arm64 内の pagefind_extended は musl を静的リンクした aarch64 バイナリです:

ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV),
statically linked, stripped

Termux 上で proot / glibc-runner なしで直接実行できます。実測結果:

./package/bin/pagefind_extended --version
# pagefind 1.5.2

./package/bin/pagefind_extended --site dist
# Indexed 21 pages

したがって、解決すべきことは次の 2 点だけです:

  1. pnpm が Android 上で @pagefind/linux-arm64 をインストールするようにする;
  2. Pagefind ラッパーが Android 上で android-arm64 ではなく linux-arm64 を検索するようにする。

修正 A:pnpm に linux-arm64 オプションパッケージをインストールさせる

pnpm-workspace.yaml に次を追加します:

supportedArchitectures:
  os:
    - current
    - linux
  cpu:
    - current
  libc:
    - current

これにより、pnpm は os: ["linux"]、cpu: ["arm64"] のオプションパッケージもリンク対象にします。Android arm64 では次がインストールされます:

node_modules/.pnpm/@pagefind+linux-arm64@1.5.2/

副作用:pnpm 11.0.9 は他のパッケージの linux-arm64 gnu/musl バリアント(sharp、rolldown、biome、lightningcss、oxc など)も一緒にインストールし、node_modules は約 680MB になります。これはインストール容量の問題であり、Android 上で実際に読み込まれるパッケージには影響しません。

修正 B:Pagefind に Android を認識させる

pnpm patch pagefind@1.5.2

node_modules/.pnpm_patches/pagefind@1.5.2/lib/resolveBinary.js を編集します:

-const platform = process.platform === "win32" ? "windows" : process.platform;
+const platform =
+  process.platform === "win32"
+    ? "windows"
+    : process.platform === "android"
+      ? "linux"
+      : process.platform;

コミットします:

pnpm patch-commit node_modules/.pnpm_patches/pagefind@1.5.2

生成:

patches/pagefind@1.5.2.patch

このマッピングは Android 以外のプラットフォームでは動作を変更しません。

注意事項

同様に、pnpm install --force を使用しないでください。以前の実測では、すべてのプラットフォームの optionalDependencies(Windows、macOS、Linux x64/mips など)をインストールし、ディスクをすぐに満杯にしてしまいました。

パッチが有効になっていない場合:

rm -rf node_modules
pnpm install --frozen-lockfile

確認:

./node_modules/.bin/pagefind --version
# pagefind 1.5.2

./node_modules/.bin/pagefind --site dist
# Indexed 21 pages

3. 最終確認

pnpm build

実際の結果:

astro check: 0 errors / 0 warnings
astro build: 48 page(s) built
pagefind:    Indexed 21 pages
pnpm test

実際の結果:

tests 13
pass 13
fail 0

build assertions passed: 21 indexed pages, 20 default RSS items
pnpm lint
# Checked 79 files. No fixes applied.

pnpm dev --host 127.0.0.1 と pnpm preview --host 127.0.0.1 はどちらも HTTP 200 を返します。Astro 7 の dev/preview はバックグラウンドで実行されるため、停止方法は次のとおりです:

pnpm exec astro dev stop
pnpm exec astro preview stop

気に入ったならばコメントを残してくださいね~