未验证 提交 80bf81a3 编写于 作者: S Steven 提交者: GitHub

Move sharp to optionalDependencies (#18068)

Co-authored-by: NTim Neutkens <tim@timneutkens.nl>
上级 9dfc9ebc
...@@ -2,14 +2,27 @@ ...@@ -2,14 +2,27 @@
#### Why This Error Occurred #### 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 #### Possible Ways to Fix It
Please install the `sharp` package in your project. Option 1: Install the `sharp` package in your project.
```bash ```bash
npm i sharp npm i sharp
# or # or
yarn add sharp 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',
},
}
```
...@@ -229,11 +229,12 @@ export async function imageOptimizer( ...@@ -229,11 +229,12 @@ export async function imageOptimizer(
sharp = require('sharp') sharp = require('sharp')
} catch (error) { } catch (error) {
if (error.code === 'MODULE_NOT_FOUND') { 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' 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 throw error
} }
......
...@@ -125,6 +125,9 @@ ...@@ -125,6 +125,9 @@
"react": "^16.6.0", "react": "^16.6.0",
"react-dom": "^16.6.0" "react-dom": "^16.6.0"
}, },
"optionalDependencies": {
"sharp": "0.26.2"
},
"devDependencies": { "devDependencies": {
"@next/polyfill-nomodule": "9.5.6-canary.9", "@next/polyfill-nomodule": "9.5.6-canary.9",
"@taskr/clear": "1.1.0", "@taskr/clear": "1.1.0",
...@@ -205,7 +208,6 @@ ...@@ -205,7 +208,6 @@
"resolve": "1.11.0", "resolve": "1.11.0",
"semver": "7.3.2", "semver": "7.3.2",
"send": "0.17.1", "send": "0.17.1",
"sharp": "0.26.2",
"source-map": "0.6.1", "source-map": "0.6.1",
"string-hash": "1.1.3", "string-hash": "1.1.3",
"strip-ansi": "6.0.0", "strip-ansi": "6.0.0",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册