Skip to content

Commit

Permalink
Ensure image-optimizer is traced for standalone mode (#32522)
Browse files Browse the repository at this point in the history
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: #32513
  • Loading branch information
ijjk committed Dec 15, 2021
1 parent 3da1f17 commit 5d606eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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

0 comments on commit 5d606eb

Please sign in to comment.