rsnext/errors/sharp-missing-in-production.mdx
Colin McDonnell 7e16538485
Include instructions for bun package manager (#53590)
## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### What?

Add instructions for using `bun/bunx` where relevant. I only added mentions where npm/yarn/pnpm were all already listed. 

### Why

Bun can be used as a runtime-agnostic [package manager](https://bun.sh/package-manager) and script runner in any project with a `package.json`.

(Sorry, I probably should have consolidated this with https://github.com/vercel/next.js/pull/53467)

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-08-10 23:44:20 +00:00

47 lines
1.8 KiB
Text

---
title: Sharp Missing In Production
---
## Why This Error Occurred
The `next/image` component's default loader uses [`squoosh`](https://www.npmjs.com/package/@squoosh/lib) 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`](https://www.npmjs.com/package/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`](https://www.npmjs.com/package/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:
```bash filename="Terminal"
npm i sharp
```
```bash filename="Terminal"
yarn add sharp
```
```bash filename="Terminal"
pnpm add sharp
```
```bash filename="Terminal"
bun 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.
## Useful Links
- [Image Optimization Documentation](/docs/pages/building-your-application/optimizing/images)
- [`next/image` Documentation](/docs/pages/api-reference/components/image)
- [Output File Tracing](/docs/pages/api-reference/next-config-js/output)