From e475d9e47f5aaa3384591f7460321be99c7bd468 Mon Sep 17 00:00:00 2001 From: Dmitri Pyatkov Date: Sun, 17 Oct 2021 20:10:28 +0700 Subject: [PATCH] Improve error message on Windows for version conflict (#2918) --- lib/sharp.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/sharp.js b/lib/sharp.js index 95874866..7d0b72ed 100644 --- a/lib/sharp.js +++ b/lib/sharp.js @@ -19,6 +19,14 @@ try { help.push( '- Consult the installation documentation: https://sharp.pixelplumbing.com/install' ); + // Check loaded + if (process.platform === 'win32') { + const loadedModule = Object.keys(require.cache).find((i) => /[\\/]build[\\/]Release[\\/]sharp(.*)\.node$/.test(i)); + if (loadedModule) { + const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/); + help.push(`- Ensure version aligns with: "npm ls sharp". Now sharp already loaded in: "${loadedPackage}"`); + } + } console.error(help.join('\n')); process.exit(1); }