Closed7

AstroのサイトをBunで動かしたい

haxibamihaxibami

まずは雑に動かしてみる

アイテム バージョン
bun 1.0.29
astro 4.4.4

https://github.com/haxibami/haxibami.net

bun install
bunx --bun astro dev # --bun で bun のランタイムを強制
bunx --bun astro build

だいたい動いているように見える

haxibamihaxibami

Nodeにさよならを

実行中にps -ef | grep node すると node という名前のバイナリが動いているように見える

haxibami   49930   49929  2 14:43 pts/2    00:00:01 node /home/haxibami/tmp/haxibami.net/node_modules/.bin/astro preview
haxibami   49963   49930  0 14:43 pts/2    00:00:00 /home/haxibami/tmp/haxibami.net/node_modules/@esbuild/linux-x64/bin/esbuild --service=0.19.12 --ping

本当に bun のランタイムで動いているのか? 確かめるべく Node.js を削除し、もう一度実行

paru -Rs nodejs node-gyp nodejs-nopt npm semver
bunx --bun run dev

普通に動いた。node という名前のバイナリは Bun のラッパーっぽい

せっかくなのでついでにクリーンインストールからやってみる

rm -r ./node_modules/
rm -r ~/.bun/install/cache/
rm bun.lockb
bun install
haxibamihaxibami

いくつかのエラーに遭遇

Sharpのインストールスクリプトがコケる

二通りのインストール方法のいずれも失敗

1. システムの libvips を使う(sharp をインストール時にビルドする)場合

  • libvips がシステムにインストールされていると自動的にこっちになる
  • node-gyp が必要

結果

  • node-gypdevDependencies に加えてから bun install を実行したが、InvalidPort のエラーを吐いて sharp のビルドが失敗
  • node-gyp をグローバルインストール(bun add -g node-gyp)した状態でも試したが結果は同じ

2. ビルド済みの libvipssharp を使う場合

  • SHARP_IGNORE_GLOBAL_LIBVIPS=1 bun install

結果

  • Bun の zlib では brotli が扱えないらしく、ダウンロードした libvipstar.br が解凍できず、失敗

https://github.com/oven-sh/bun/issues/267

  • 2年以上直っていない
haxibamihaxibami

Pagefindが動かない

pagefind のインデックスも Bun のランタイムで走らせてみる

bun run --bun postbuild

$ pagefind --site dist /tmp/pagefind.txt
Failed to run pagefind via the npx wrapper: Error: Invalid stdio option "[object ReadStream]"
Please open an issue at https://github.com/CloudCannon/pagefind and paste this error message in full.
error: script "postbuild" exited with code 1

https://github.com/oven-sh/bun/issues/7959

残念〜

haxibamihaxibami

また会えたね Node

あきらめてNodeを再インストール

paru -S nodejs node-gyp nodejs-nopt npm semver
  • bun install のエラーは Node がインストールされていれば解消する
  • pagefind のインデックスは --bun オプションを付けずに(Node上で)動かす必要あり

まとめると

コマンド Bunでの動作の可否
bun install △(Node.js がインストールされていれば動作)
astro {dev,build,preview}
pagefind ×

面倒なので Bun 移行はいったん保留

このスクラップは4ヶ月前にクローズされました