diff --git a/docs/changelog.md b/docs/changelog.md index 15ac8e12..dbcbf121 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,10 @@ Requires libvips v8.7.4. [#1601](https://github.com/lovell/sharp/pull/1601) [@Goues](https://github.com/Goues) +* Improve help messaging should `require("sharp")` fail. + [#1638](https://github.com/lovell/sharp/pull/1638) + [@sidharthachatterjee](https://github.com/sidharthachatterjee) + #### v0.22.0 - 18th March 2019 * Remove functions previously deprecated in v0.21.0: diff --git a/lib/constructor.js b/lib/constructor.js index 0f85b02a..3924d050 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -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 diff --git a/package.json b/package.json index 389c447c..d724db77 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,6 @@ "vips" ], "dependencies": { - "bindings": "^1.5.0", "color": "^3.1.0", "detect-libc": "^1.0.3", "fs-copy-file-sync": "^1.1.1",