Enhancement to and changelog entry for #1638

Remove bindings dependency as this isn't really... required
This commit is contained in:
Lovell Fuller
2019-04-02 20:39:03 +01:00
parent 2e0fbbb942
commit 687795c801
3 changed files with 19 additions and 14 deletions

View File

@@ -9,22 +9,24 @@ const is = require('./is');
require('./libvips').hasVendoredLibvips();
let sharp;
try {
sharp = require('bindings')('sharp.node');
} catch (error) {
sharp = require('../build/Release/sharp.node');
} catch (err) {
// Bail early if bindings aren't available
console.error(
`
"sharp" does not seem to have been built or installed correctly.
- Try to reinstall packages and look for errors during installation
- Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/
If neither of the above work, please open an issue in https://github.com/lovell/sharp/issues
`
const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, ''];
if (/NODE_MODULE_VERSION/.test(err.message)) {
help.push('- Ensure the version of Node.js used at install time matches that used at runtime');
} else if (/invalid ELF header/.test(err.message)) {
help.push(`- Ensure "${process.platform}" is used at install time as well as runtime`);
} else {
help.push('- Remove the "node_modules/sharp" directory, run "npm install" and look for errors');
}
help.push(
'- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/',
'- Search for this error at https://github.com/lovell/sharp/issues', ''
);
throw error;
console.error(help.join('\n'));
process.exit(1);
}
// Use NODE_DEBUG=sharp to enable libvips warnings