From 850219e72bc0ec818d3989704819fd89cfd49f50 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Tue, 2 Feb 2021 01:02:18 +0000 Subject: [PATCH] only ignore sharp if it's installed --- packages/next/build/index.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 0ca466995703f..a5d666e71defd 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -395,6 +395,17 @@ export default async function build( PAGES_MANIFEST ) + // `sharp` is optional so may not be installed + const ignore: string[] = [] + try { + ignore.push( + path.relative( + dir, + path.join(path.dirname(require.resolve('sharp')), '**/*') + ) + ) + } catch {} + const requiredServerFiles = traceFn( tracer.startSpan('generate-required-server-files'), () => ({ @@ -420,12 +431,7 @@ export default async function build( ] .filter(nonNullable) .map((file) => path.join(config.distDir, file)), - ignore: [ - path.relative( - dir, - path.join(path.dirname(require.resolve('sharp')), '**/*') - ), - ], + ignore, }) )