はじめに
bun を使って Vite で環境構築した際に、 title のエラーが発生したので解消法をまとめておきます
問題
Bun を使って Vite や Biome などの CLI を使おうとすると、ネイティブモジュールが見つけられないというエラーが発生する
bun run vite
Error: Cannot find module @rollup/rollup-darwin-x64. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
解決方法
--bun
フラグを付与する
bun run --bun vite
Bunは独自のJavaScriptエンジンを使用しているらしく、Node.jsとネイティブモジュールの扱い方が異なるようです
--bun
フラグを使用する事で、Bunの独自実装を使用することを指定することができエラーを回避できるようです
参考
https://github.com/oven-sh/bun/issues/11511
https://bun.sh/docs/cli/run#bun