Unverified Commit 5d606eba authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure image-optimizer is traced for standalone mode (#32522)

This ensures we trace the `image-optimizer` for the standalone output mode as previously this was always ignored under the assumption image optimizing would be handled at the CDN level in standalone mode. 

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`

Fixes: https://github.com/vercel/next.js/issues/32513
parent 3da1f17d
...@@ -1242,12 +1242,18 @@ export default async function build( ...@@ -1242,12 +1242,18 @@ export default async function build(
processCwd: dir, processCwd: dir,
ignore: [ ignore: [
'**/next/dist/pages/**/*', '**/next/dist/pages/**/*',
'**/next/dist/server/image-optimizer.js',
'**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*', '**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js', '**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/sharp/**/*',
'**/node_modules/webpack5/**/*', '**/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/**/*',
]
: []),
], ],
} }
) )
......
...@@ -387,6 +387,19 @@ export async function imageOptimizer( ...@@ -387,6 +387,19 @@ export async function imageOptimizer(
optimizedBuffer = await transformer.toBuffer() optimizedBuffer = await transformer.toBuffer()
// End sharp transformation logic // End sharp transformation logic
} else { } 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 // Show sharp warning in production once
if (showSharpMissingWarning) { if (showSharpMissingWarning) {
console.warn( console.warn(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment