rsnext/errors/sharp-missing-in-production.md
Balázs Orbán cbda3b52dc
docs(image): improve error message when sharp is missing in standalone mode (#41133)
Partially addresses #41111

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-05 17:28:29 +00:00

1.7 KiB

Sharp Missing In Production

Why This Error Occurred

The next/image component's default loader uses squoosh because it is quick to install and suitable for a development environment.

  • For a production environment using next start, it is strongly recommended you install sharp.

You are seeing this error because Image Optimization in production mode (next start) was detected.

  • For a production environment using output: "standalone", you must install sharp.

You are seeing this error because Image Optimization in standalone mode (output: "standalone") was detected.

Possible Ways to Fix It

  • Install sharp by running one of the following commands in your project directory:
npm i sharp
yarn add sharp
pnpm add sharp

Then, build your project with next build. Finally, restart the server with either next start for production mode or node server.js for standalone mode.

  • If sharp is already installed but can't be resolved, set the NEXT_SHARP_PATH environment variable such as export NEXT_SHARP_PATH=/tmp/node_modules/sharp. Then, build your project with next build. Finally, restart the server with either next start for production mode or node server.js for standalone mode.

Note: This is not necessary for Vercel deployments, since sharp is installed automatically for you.