From 75ef61a95841bb1eaa39bd10a9500ed8f7e172a0 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 10 Nov 2023 16:30:01 +0100 Subject: [PATCH] Correctly check for when sharp is unavailable (#3848) --- lib/sharp.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sharp.js b/lib/sharp.js index 7c382859..af18adec 100644 --- a/lib/sharp.js +++ b/lib/sharp.js @@ -17,10 +17,11 @@ const paths = [ '@img/sharp-wasm32/sharp.node' ]; +let sharp; const errors = []; for (const path of paths) { try { - module.exports = require(path); + sharp = require(path); break; } catch (err) { /* istanbul ignore next */ @@ -29,7 +30,9 @@ for (const path of paths) { } /* istanbul ignore next */ -if (!module.exports) { +if (sharp) { + module.exports = sharp; +} else { const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os)); const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];