Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sharp to optionalDependencies #18068

Merged
merged 3 commits into from Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions errors/install-sharp.md
Expand Up @@ -2,14 +2,27 @@

#### Why This Error Occurred

Using Next.js' built-in Image Optimization requires that you bring your own version of `sharp`.
Using Next.js' built-in Image Optimization requires that you install `sharp`.

Since `sharp` is optional, it may have been skipped if you installed `next` with the [`--no-optional`](https://docs.npmjs.com/cli/install) flag or it may have been skipped if your platform does not support `sharp`.

#### Possible Ways to Fix It

Please install the `sharp` package in your project.
Option 1: Install the `sharp` package in your project.

```bash
npm i sharp
# or
yarn add sharp
```

Option 2: Configure an external loader in `next.config.js` such as [imgix](https://imgix.com).

```js
module.exports = {
images: {
path: 'https://example.com/myaccount/',
loader: 'imgix',
},
}
```
9 changes: 5 additions & 4 deletions packages/next/next-server/server/image-optimizer.ts
Expand Up @@ -229,11 +229,12 @@ export async function imageOptimizer(
sharp = require('sharp')
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
error.message +=
"\nTo use Next.js' built-in Image Optimization, you first need to install `sharp`."
error.message +=
'\nRun `npm i sharp` or `yarn add sharp` inside your workspace.'
error.message += '\n\nLearn more: https://err.sh/next.js/install-sharp'
server.logError(error)
if (upstreamType) {
res.setHeader('Content-Type', upstreamType)
}
res.end(upstreamBuffer)
}
throw error
}
Expand Down
4 changes: 3 additions & 1 deletion packages/next/package.json
Expand Up @@ -125,6 +125,9 @@
"react": "^16.6.0",
"react-dom": "^16.6.0"
},
"optionalDependencies": {
"sharp": "0.26.2"
},
"devDependencies": {
"@next/polyfill-nomodule": "9.5.6-canary.9",
"@taskr/clear": "1.1.0",
Expand Down Expand Up @@ -205,7 +208,6 @@
"resolve": "1.11.0",
"semver": "7.3.2",
"send": "0.17.1",
"sharp": "0.26.2",
"source-map": "0.6.1",
"string-hash": "1.1.3",
"strip-ansi": "6.0.0",
Expand Down