Skip to content

Commit b6a758a

Browse files
committed
Check for exceptions while resolving path to sharp
1 parent 5e5d792 commit b6a758a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/next/build/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ export default async function build(
360360
PAGES_MANIFEST
361361
)
362362

363+
// Sharp is optional.
364+
let sharpPath: string | null = null
365+
try {
366+
sharpPath = path.relative(
367+
dir,
368+
path.join(path.dirname(require.resolve('sharp')), '**/*')
369+
)
370+
} catch (e) {}
371+
363372
const requiredServerFiles = {
364373
version: 1,
365374
config: {
@@ -383,12 +392,7 @@ export default async function build(
383392
]
384393
.filter(nonNullable)
385394
.map((file) => path.join(config.distDir, file)),
386-
ignore: [
387-
path.relative(
388-
dir,
389-
path.join(path.dirname(require.resolve('sharp')), '**/*')
390-
),
391-
],
395+
ignore: [sharpPath].filter(nonNullable),
392396
}
393397

394398
const configs = await Promise.all([

0 commit comments

Comments
 (0)