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

fix(next): add missing optional peer dependency sharp #17981

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion packages/next/next-server/server/image-optimizer.ts
Expand Up @@ -225,7 +225,6 @@ export async function imageOptimizer(

if (!sharp) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
sharp = require('sharp')
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
Expand Down
8 changes: 7 additions & 1 deletion packages/next/package.json
Expand Up @@ -123,7 +123,13 @@
},
"peerDependencies": {
"react": "^16.6.0",
"react-dom": "^16.6.0"
"react-dom": "^16.6.0",
"sharp": "0.26.2"
},
"peerDependenciesMeta": {
"sharp": {
"optional": true
}
Comment on lines +126 to +132
Copy link
Member

@styfle styfle Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"react-dom": "^16.6.0",
"sharp": "0.26.2"
},
"peerDependenciesMeta": {
"sharp": {
"optional": true
}
"react-dom": "^16.6.0"
},
"optionalDependencies": {
"sharp": "^0.26.2"
}

Let's use optionalDependencies instead.

Also remove it from devDependencies since this will install by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, it will always be installed, based on the error defined here

if (!sharp) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
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'
}
throw error
}
}
and here https://github.com/vercel/next.js/blob/17cddcb92a329c87d1bb05baa62dd6e8d4c1fc9a/errors/install-sharp.md that is not what you want

https://yarnpkg.com/configuration/manifest#optionalDependencies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove that message after changing to optionalDependencies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@styfle This doesn't look great. Next.js is very bloated package.
https://packagephobia.com/result?p=next@10.0.0

},
"devDependencies": {
"@next/polyfill-nomodule": "9.5.6-canary.4",
Expand Down