Correctly check for when sharp is unavailable (#3848)

This commit is contained in:
Pooya Parsa 2023-11-10 16:30:01 +01:00 committed by GitHub
parent 2dba5b5451
commit 75ef61a958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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`];