1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const platformAndArch = require('./platform')();
|
7 |
|
8 |
|
9 | try {
|
10 | module.exports = require(`../build/Release/sharp-${platformAndArch}.node`);
|
11 | } catch (err) {
|
12 |
|
13 | const help = ['', 'Something went wrong installing the "sharp" module', '', err.message, '', 'Possible solutions:'];
|
14 | if (/dylib/.test(err.message) && /Incompatible library version/.test(err.message)) {
|
15 | help.push('- Update Homebrew: "brew update && brew upgrade vips"');
|
16 | } else {
|
17 | const [platform, arch] = platformAndArch.split('-');
|
18 | if (platform === 'linux' && /Module did not self-register/.test(err.message)) {
|
19 | help.push('- Using worker threads? See https://sharp.pixelplumbing.com/install#worker-threads');
|
20 | }
|
21 | help.push(
|
22 | '- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"',
|
23 | `- Install for the current ${platformAndArch} runtime: "npm install --platform=${platform} --arch=${arch} sharp"`
|
24 | );
|
25 | }
|
26 | help.push(
|
27 | '- Consult the installation documentation: https://sharp.pixelplumbing.com/install'
|
28 | );
|
29 |
|
30 | if (process.platform === 'win32' || /symbol/.test(err.message)) {
|
31 | const loadedModule = Object.keys(require.cache).find((i) => /[\\/]build[\\/]Release[\\/]sharp(.*)\.node$/.test(i));
|
32 | if (loadedModule) {
|
33 | const [, loadedPackage] = loadedModule.match(/node_modules[\\/]([^\\/]+)[\\/]/);
|
34 | help.push(`- Ensure the version of sharp aligns with the ${loadedPackage} package: "npm ls sharp"`);
|
35 | }
|
36 | }
|
37 | throw new Error(help.join('\n'));
|
38 | }
|