Back to Next Js

Install `sharp` to Use Built-In Image Optimization

errors/install-sharp.mdx

16.2.51.2 KB
Original Source

Why This Error Occurred

Using Next.js' built-in Image Optimization requires sharp as a dependency.

You are seeing this error because your OS was unable to install sharp properly, either using pre-built binaries or building from source.

Possible Ways to Fix It

Option 1: Use a different version of Node.js and try to install sharp again.

bash
npm i sharp
bash
yarn add sharp
bash
pnpm add sharp
bash
bun add sharp

Option 2: Try installing the wasm variant of sharp by running npm install --cpu=wasm32 sharp.

Option 3: If using macOS, ensure XCode Build Tools are installed and try to install sharp again.

For example, see macOS Catalina instructions.

Option 4: Use a different OS and try to install sharp again.

For example, if you're using Windows, try using WSL (Windows Subsystem for Linux).