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

Ensure image-optimizer is traced for standalone mode #32522

Merged
merged 2 commits into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions packages/next/build/index.ts
Expand Up @@ -1242,12 +1242,18 @@ export default async function build(
processCwd: dir,
ignore: [
'**/next/dist/pages/**/*',
'**/next/dist/server/image-optimizer.js',
'**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/sharp/**/*',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
...(ciEnvironment.hasNextSupport
? [
// only ignore image-optimizer code when
// this is being handled outside of next-server
'**/next/dist/server/image-optimizer.js',
'**/node_modules/sharp/**/*',
]
: []),
],
}
)
Expand Down
13 changes: 13 additions & 0 deletions packages/next/server/image-optimizer.ts
Expand Up @@ -387,6 +387,19 @@ export async function imageOptimizer(
optimizedBuffer = await transformer.toBuffer()
// End sharp transformation logic
} else {
if (
showSharpMissingWarning &&
nextConfig.experimental?.outputStandalone
) {
// TODO: should we ensure squoosh also works even though we don't
// recommend it be used in production and this is a production feature
console.error(
`Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly`
)
req.statusCode = 500
res.end('internal server error')
return { finished: true }
}
// Show sharp warning in production once
if (showSharpMissingWarning) {
console.warn(
Expand Down