[Next.js/Vercel] “Error: Could not load the “sharp” module using the linux-x64 runtime” というエラーが出る時の解決方法

Next.js

“Error: Could not load the “sharp” module using the linux-x64 runtime” というエラーが出る時の解決方法について説明します。

広告

ローカル環境では問題なく動作していましたが、Vercelにデプロイ後、以下のようなエラーが発生しました。


Error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Ensure optional dependencies can be installed:
    npm install --include=optional sharp
    yarn add sharp --ignore-engines
- Ensure your package manager supports multi-platform installation:
    See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
    npm install --force @img/sharp-linux-x64
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install

画像処理のライブラリSharpが原因のエラーです。上記のエラーメッセージのコマンドを実行しても解決しませんでした。

解決方法: Sharpを0.32.6にダウングレード

Sharpのバージョンを0.33.1から0.32.6に変更したら、エラーが発生しなくなりました。

npm install sharp@0.32.6

根本的な問題は解決していませんが、他の解決方法が見つからなかったので、しばらくはこれで凌ぎます。

参考ページ

Vercel only: 0.33.0: error Could not load the “sharp” module using the linux-x64 runtime

広告