From 2e0fbbb9423d781025e7f459800a029745729e4e Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Apr 2019 21:30:55 +0530 Subject: [PATCH] Add warning if sharp bindings aren't built correctly (#1638) --- lib/constructor.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/constructor.js b/lib/constructor.js index c8ac4516..0f85b02a 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -7,7 +7,25 @@ const events = require('events'); const is = require('./is'); require('./libvips').hasVendoredLibvips(); -const sharp = require('bindings')('sharp.node'); + +let sharp; + +try { + sharp = require('bindings')('sharp.node'); +} catch (error) { + // 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 + ` + ); + throw error; +} // Use NODE_DEBUG=sharp to enable libvips warnings const debuglog = util.debuglog('sharp');