【JS】sharpで突如謎のエラー、rebuildで解決
こんにちは!今年は楽しい誕生日を迎えられたMizutani(@sirycity)です。去年の29→30歳は地獄だった。
今日はJavaScriptのパッケージ、sharpが突如コケるようになったのでその対策。
結論
ビルド前に npm rebuild --verbose sharp
sharpについて
sharpはjs製の画像加工のライブラリです。ImageMagickとかの仲間。まあだからよく使うんだ。
しかしこいつ11月の上旬ごろから謎のエラーを吐くようになって
[vite] (ssr) Error when evaluating SSR module:
Something went wrong installing the "sharp" module
Cannot find module '../build/Release/sharp-darwin-arm64v8.node'
Require stack:
- /node_modules/astro-webmanifest/node_modules/sharp/lib/sharp.js
- /node_modules/astro-webmanifest/node_modules/sharp/lib/constructor.js
- /node_modules/astro-webmanifest/node_modules/sharp/lib/index.js
Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-arm64v8 runtime: "npm install --platform=darwin --arch=arm64v8 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
この有り様。ちなみに案内されてるnpmコマンド打っても駄目。
解決方法
あった。天才か?
Cannot find module ’../build/Release/sharp-linux-x64.node’ #3717
npm rebuild --verbose sharp
タイミング的には install→これ→build でOK。
最後に
sharp、やたら苦しめてくるけど便利だからとても離れられない。このブログもOGP自動生成してる。多分これからも頑張って付き合い続ける持病のようなライブラリになるでしょう。以上。
PREV
2025-11-17
Vivaldiの下のメニューバーを消そう
NEXT
2025-12-14
【JS】画像の名前に半角スペース入れたらsrcsetでエラーになる