From a8a0c1e935dbb6fa1053d6bdb8d5af18ff3b4260 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 10 Jan 2020 16:29:40 +0000 Subject: [PATCH] Update doc links contained within code Throw rather than exit if require fails --- .github/ISSUE_TEMPLATE/installation.md | 2 ++ install/libvips.js | 2 +- lib/constructor.js | 13 +++++++++---- src/common.h | 6 +++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/installation.md b/.github/ISSUE_TEMPLATE/installation.md index fbea24a0..df97cbbb 100644 --- a/.github/ISSUE_TEMPLATE/installation.md +++ b/.github/ISSUE_TEMPLATE/installation.md @@ -13,6 +13,8 @@ Have you ensured the platform and version of Node.js used for `npm install` is t If you are installing as a `root` or `sudo` user, have you tried with the `npm install --unsafe-perm` flag? +If you are using the `ignore-scripts` feature of `npm`, have you tried with the `npm install --ignore-scripts=false` flag? + What is the complete output of running `npm install --verbose sharp`? Have you checked this output for useful error messages? What is the output of running `npx envinfo --binaries --languages --system --utilities`? diff --git a/install/libvips.js b/install/libvips.js index 7b58041d..97a36a3a 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -23,7 +23,7 @@ const fail = function (err) { npmLog.info('sharp', 'Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag'); } npmLog.info('sharp', 'Attempting to build from source via node-gyp but this may fail due to the above error'); - npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/page/install for required dependencies'); + npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/install for required dependencies'); process.exit(1); }; diff --git a/lib/constructor.js b/lib/constructor.js index ad475c44..2465bf42 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -16,15 +16,20 @@ try { 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 if (/Cannot find module/.test(err.message)) { + help.push('- Run "npm rebuild --verbose sharp" and look for errors'); } else { - help.push('- Remove the "node_modules/sharp" directory, run "npm install" and look for errors'); + help.push( + '- Remove the "node_modules/sharp" directory then run', + ' "npm install --ignore-scripts=false --verbose" and look for errors' + ); } help.push( - '- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/', + '- Consult the installation documentation at https://sharp.pixelplumbing.com/install', '- Search for this error at https://github.com/lovell/sharp/issues', '' ); - console.error(help.join('\n')); - process.exit(1); + const error = help.join('\n'); + throw new Error(error); } // Use NODE_DEBUG=sharp to enable libvips warnings diff --git a/src/common.h b/src/common.h index 69d52273..088d05d2 100644 --- a/src/common.h +++ b/src/common.h @@ -26,16 +26,16 @@ // Verify platform and compiler compatibility #if (VIPS_MAJOR_VERSION < 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 9)) -#error libvips version 8.9.0+ is required - see sharp.pixelplumbing.com/page/install +#error "libvips version 8.9.0+ is required - please see https://sharp.pixelplumbing.com/install" #endif #if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6))) -#error GCC version 4.6+ is required for C++11 features - see sharp.pixelplumbing.com/page/install#prerequisites +#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install" #endif #if (defined(__clang__) && defined(__has_feature)) #if (!__has_feature(cxx_range_for)) -#error clang version 3.0+ is required for C++11 features - see sharp.pixelplumbing.com/page/install#prerequisites +#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install" #endif #endif