Improve error message on Windows for version conflict (#2918)

This commit is contained in:
Dmitri Pyatkov
2021-10-17 20:10:28 +07:00
committed by GitHub
parent f37ca8249a
commit e475d9e47f

View File

@@ -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);
}