Check if sharp is failing on bundle before running image minimizer

pull/9022/head
Aditya Toshniwal 2025-08-04 12:34:56 +05:30
parent 1316a3d7d8
commit 86c2769221
1 changed files with 4 additions and 2 deletions

View File

@ -28,8 +28,10 @@ const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
let isSharpAvailable = true; let isSharpAvailable = true;
try { try {
require.resolve('sharp'); const sharp = require('sharp');
} catch (e) { // It is possible that sharp is installed but fails on running
sharp();
} catch {
isSharpAvailable = false; isSharpAvailable = false;
console.warn('Sharp is not available, image optimization will be disabled.'); console.warn('Sharp is not available, image optimization will be disabled.');
} }