lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.16k stars 1.29k forks source link

Something went wrong installing the "sharp" module #2517

Closed its-dibo closed 3 years ago

its-dibo commented 3 years ago

update: the issue is probably caused by webpack-node-externals. https://github.com/lovell/sharp/issues/2517#issuecomment-772827876


I use sharp but I got this error:

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011
  throw new Error(error);
  ^

Error:
Something went wrong installing the "sharp" module

node-loader:
Error: The specified module could not be found.
D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server/33c1e48f049ce3285905e286d212a201.node

- Remove the "node_modules/sharp" directory then run
  "npm install --ignore-scripts=false --verbose" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

    at Object.EmBj (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:150011:9)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Object.Tbcg (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:251632:15)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.dMKD (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:324313:63)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.mWHM (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:405859:77)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.WXK/ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:271250:65)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:118:18
    at Object.<anonymous> (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:121:10)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1156:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1000:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:899:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.js:18:47←[39m

minimal reproduction: https://github.com/lovell/sharp/issues/2517#issuecomment-767703678

I removed sharp from 'node_modules` then reinstalled it, but got the same error

> npm cache clean -f
> npm i --verbose sharp@latest

the verbose output of installing sharp is:


D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx>npm i --verbose sharp@latest
npm info it worked if it ends with ok
npm verb cli [
npm verb cli   'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\eldeeb\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'i',
npm verb cli   '--verbose',
npm verb cli   'sharp@latest'
npm verb cli ]
npm info using npm@6.9.0
npm info using node@v12.16.2
npm verb npm-session c41d87c77d3d7180
npm http fetch GET 200 https://registry.npmjs.org/sharp 1417ms
npm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.27.0.tgz 644ms
npm timing stage:loadCurrentTree Completed in 6364ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 37ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1936ms
npm http fetch GET 200 https://registry.npmjs.org/array-flatten 218ms
npm http fetch GET 200 https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz 278ms
npm http fetch GET 200 https://registry.npmjs.org/prebuild-install 507ms
npm http fetch GET 200 https://registry.npmjs.org/npmlog 511ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get 545ms
npm http fetch GET 200 https://registry.npmjs.org/tar-fs 638ms
npm http fetch GET 200 https://registry.npmjs.org/semver 643ms
npm http fetch GET 200 https://registry.npmjs.org/node-addon-api 654ms
npm http fetch GET 200 https://registry.npmjs.org/detect-libc 659ms
npm http fetch GET 200 https://registry.npmjs.org/prebuild-install/-/prebuild-install-6.0.0.tgz 156ms
npm http fetch GET 200 https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz 158ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-4.0.0.tgz 151ms
npm http fetch GET 200 https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz 468ms
npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-7.3.4.tgz 471ms
npm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz 464ms
npm http fetch GET 200 https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz 644ms
npm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet 122ms
npm http fetch GET 200 https://registry.npmjs.org/gauge 306ms
npm http fetch GET 200 https://registry.npmjs.org/console-control-strings 319ms
npm http fetch GET 200 https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz 424ms
npm http fetch GET 200 https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz 436ms
npm http fetch GET 200 https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz 626ms
npm http fetch GET 200 https://registry.npmjs.org/delegates 182ms
npm http fetch GET 200 https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz 355ms
npm http fetch GET 200 https://registry.npmjs.org/has-unicode 150ms
npm http fetch GET 200 https://registry.npmjs.org/wide-align 158ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi 166ms
npm http fetch GET 200 https://registry.npmjs.org/string-width 170ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz 216ms
npm http fetch GET 200 https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz 232ms
npm http fetch GET 200 https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz 242ms
npm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz 323ms
npm http fetch GET 200 https://registry.npmjs.org/code-point-at 248ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point 260ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz 335ms
npm http fetch GET 200 https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz 364ms
npm http fetch GET 200 https://registry.npmjs.org/number-is-nan 221ms
npm http fetch GET 200 https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz 198ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex 294ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz 235ms
npm http fetch GET 200 https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz 129ms
npm http fetch GET 200 https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz 659ms
npm http fetch GET 200 https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz 673ms
npm http fetch GET 200 https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz 167ms
npm http fetch GET 200 https://registry.npmjs.org/expand-template 196ms
npm http fetch GET 200 https://registry.npmjs.org/which-pm-runs 441ms
npm http fetch GET 200 https://registry.npmjs.org/noop-logger 445ms
npm http fetch GET 200 https://registry.npmjs.org/node-abi 449ms
npm http fetch GET 200 https://registry.npmjs.org/napi-build-utils 456ms
npm http fetch GET 200 https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz 448ms
npm http fetch GET 200 https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz 263ms
npm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic 473ms
npm http fetch GET 200 https://registry.npmjs.org/github-from-package 479ms
npm http fetch GET 200 https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz 549ms
npm http fetch GET 200 https://registry.npmjs.org/node-abi/-/node-abi-2.19.3.tgz 557ms
npm http fetch GET 200 https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz 575ms
npm http fetch GET 200 https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz 580ms
npm http fetch GET 200 https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz 561ms
npm http fetch GET 200 https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz 571ms
npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-5.7.1.tgz 336ms
npm http fetch GET 200 https://registry.npmjs.org/simple-concat 280ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response 299ms
npm http fetch GET 200 https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz 131ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz 147ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response 213ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz 183ms
npm http fetch GET 200 https://registry.npmjs.org/tar-stream 206ms
npm http fetch GET 200 https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz 293ms
npm http fetch GET 200 https://registry.npmjs.org/fs-constants 162ms
npm http fetch GET 200 https://registry.npmjs.org/bl 202ms
npm http fetch GET 200 https://registry.npmjs.org/readable-stream 228ms
npm http fetch GET 200 https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz 188ms
npm http fetch GET 200 https://registry.npmjs.org/bl/-/bl-4.0.3.tgz 157ms
npm http fetch GET 200 https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz 154ms
npm http fetch GET 200 https://registry.npmjs.org/buffer 858ms
npm http fetch GET 200 https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz 159ms
npm http fetch GET 200 https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz 245ms
npm http fetch GET 200 https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz 105ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 17386ms
npm timing stage:loadIdealTree Completed in 20212ms
npm timing stage:generateActionsToTake Completed in 251ms
npm verb correctMkdir C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks correctMkdir not in flight; initializing
npm verb makeDirectory C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks creation not in flight; initializing
npm verb makeCacheDir UID & GID are irrelevant on win32
npm verb lock using C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock for D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.stag
ing
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 250ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz 260ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz 255ms
npm timing action:extract Completed in 304ms
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm timing action:unbuild Completed in 10ms
npm timing action:remove Completed in 0ms
npm timing action:finalize Completed in 60ms
npm timing action:refresh-package-json Completed in 105ms
npm info lifecycle array-flatten@3.0.0~preinstall: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~preinstall: semver@7.3.4
npm info lifecycle sharp@0.27.0~preinstall: sharp@0.27.0
npm timing action:preinstall Completed in 17ms
npm info linkStuff array-flatten@3.0.0
npm info linkStuff semver@7.3.4
npm verb linkBins [
npm verb linkBins   { semver: 'bin/semver.js' },
npm verb linkBins   'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\node_modules\\sharp\\node_modules\\.bin',
npm verb linkBins   false
npm verb linkBins ]
npm info linkStuff sharp@0.27.0
npm timing action:build Completed in 70ms
npm info lifecycle array-flatten@3.0.0~install: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~install: semver@7.3.4
npm info lifecycle sharp@0.27.0~install: sharp@0.27.0

> sharp@0.27.0 install D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.5/libvips-8.10.5-win32-x64.tar.br
info sharp Creating D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release
info sharp Copying DLLs from D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\vendor\8.10.5\lib to D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\nod
e_modules\sharp\build\Release
prebuild-install info begin Prebuild-install version 6.0.0
prebuild-install info looking for cached prebuild @ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\eldeeb\AppData\Roaming\npm-cache\_prebuilds\9cc5aa-sharp-v0.27.0-napi-v3-win32-x64.tar.gz
prebuild-install info unpack resolved to D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp\build\Release\sharp.node
prebuild-install info install Successfully installed prebuilt binary!
npm verb lifecycle sharp@0.27.0~install: unsafe-perm in lifecycle true
npm verb lifecycle sharp@0.27.0~install: PATH: C:\Users\eldeeb\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\Downloads\__projects\dev\No
deJs\@eng-dibo\ngx\node_modules\sharp\node_modules\.bin;D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\.bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Pr
ogram Files\Intel\iCLS Client\;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\
Program Files (x86)\WinMerge;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program
Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\
Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files (x86)\Yar
n\bin\;C:\Program Files\heroku\bin;C:\Users\eldeeb\AppData\Roaming\npm;C:\Users\eldeeb\AppData\Local\atom\bin;C:\Users\eldeeb\AppData\Local\Yarn\bin
npm verb lifecycle sharp@0.27.0~install: CWD: D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_modules\sharp
npm timing audit submit Completed in 6102ms
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 6102ms
npm timing audit body Completed in 1ms
npm timing action:install Completed in 30506ms
npm info lifecycle array-flatten@3.0.0~postinstall: array-flatten@3.0.0
npm info lifecycle semver@7.3.4~postinstall: semver@7.3.4
npm info lifecycle sharp@0.27.0~postinstall: sharp@0.27.0
npm timing action:postinstall Completed in 9ms
npm verb unlock done using C:\Users\eldeeb\AppData\Roaming\npm-cache\_locks\staging-ff976866a950c511.lock for D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\node_module
s\.staging
npm timing stage:executeActions Completed in 31157ms
npm timing stage:rollbackFailedOptional Completed in 19ms
npm timing stage:runTopLevelLifecycles Completed in 58678ms
npm verb saving [ { name: 'sharp', spec: '^0.27.0', save: 'dependencies' } ]
npm verb shrinkwrap skipping write for package.json because there were no changes.
npm info lifecycle undefined~preshrinkwrap: undefined
npm info lifecycle undefined~shrinkwrap: undefined
npm verb shrinkwrap skipping write for package-lock.json because there were no changes.
npm info lifecycle undefined~postshrinkwrap: undefined
npm WARN @angular-devkit/build-angular@0.1001.7 requires a peer of @angular/localize@^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular-devkit/build-angular@0.1001.7 requires a peer of ng-packagr@^10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @fortawesome/angular-fontawesome@0.6.1 requires a peer of @angular/core@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @fortawesome/angular-fontawesome@0.6.1 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.
npm WARN jsdom@16.4.0 requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-loading@8.0.0 requires a peer of @angular/common@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ngx-loading@8.0.0 requires a peer of @angular/core@^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@10.0.1 requires a peer of node-sass@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@10.0.1 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-subresource-integrity@1.4.1 requires a peer of html-webpack-plugin@^2.21.0 || ~3 || >=4.0.0-alpha.2 <5 but none is installed. You must install peer depen
dencies yourself.
npm WARN ws@7.4.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.4.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
npm verb notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64

+ sharp@0.27.0
added 3 packages from 69 contributors and audited 1986 packages in 60.317s
found 11 vulnerabilities (7 low, 1 moderate, 3 high)
  run `npm audit fix` to fix them, or `npm audit` for details
npm verb exit [ 0, true ]
npm timing npm Completed in 60904ms
npm info ok

I added node-loader to webpack:

config.module.rules.push(
    { test: /\.ts$/, loader: "ts-loader" },
    {
      test: /\.node$/,
      use: "node-loader"
    }
  );

webpack config:

{
    mode: 'development',
    devtool: false,
    profile: false,
    resolve: {
      roots: [Array],
      extensions: [Array],
      symlinks: false,
      modules: [Array],
      plugins: [Array],
      mainFields: [Array],
      alias: [Object]
    },
    resolveLoader: { symlinks: true, modules: [Array], plugins: [Array] },
    context: 'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx',
    entry: {
      express: 'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\projects\\cms\\server\\express.ts'
    },
    output: {
      futureEmitAssets: true,
      path: 'D:\\Downloads\\__projects\\dev\\NodeJs\\@eng-dibo\\ngx\\dist\\cms\\core\\server',
      publicPath: undefined,
      filename: '[name].js',
      libraryTarget: 'commonjs-module'
    },
    watch: false,
    watchOptions: { poll: undefined, ignored: undefined },
    performance: { hints: false },
    module: { strictExportPresence: true, rules: [Array] },
    optimization: { minimizer: [], moduleIds: 'hashed', noEmitOnErrors: true },
    plugins: [
      [ContextReplacementPlugin],
      [DedupeModuleResolvePlugin],
      [ProgressPlugin],
      [CircularDependencyPlugin],
      NamedLazyChunksPlugin {},
      [BundleBudgetPlugin],
      [ContextReplacementPlugin],
      [ContextReplacementPlugin],
      [SourceMapDevToolPlugin],
      [AnyComponentStyleBudgetChecker],
      [AngularCompilerPlugin],
      [IgnoreNotFoundExportPlugin]
    ],
    target: 'node',
    node: false,
    externals: [ [Function], [Function] ],
    stats: {
      colors: true,
      hash: true,
      timings: true,
      chunks: true,
      chunkModules: false,
      children: false,
      modules: false,
      reasons: false,
      warnings: true,
      errors: true,
      assets: true,
      version: false,
      errorDetails: false,
      moduleTrace: false
    }
  }

all node_modules are added to webpack.externals OS: windows 8.1

lovell commented 3 years ago

If you're using webpack, please try adding sharp to externals - see https://webpack.js.org/configuration/externals/

its-dibo commented 3 years ago

I tried config.externals.push("sharp"); , but got ReferenceError: sharp is not defined

I already use webpack-node-externals to add all node_modules to webpack.externals

also I see a .node file have been created in dist folder

@lovell

lovell commented 3 years ago

You'll probably need to remove the use of node-loader when using externals.

its-dibo commented 3 years ago

after removing node-loader I got this error

D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:149906
  throw new Error(error);
  ^

Error:
Something went wrong installing the "sharp" module

Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

- Remove the "node_modules/sharp" directory then run
  "npm install --ignore-scripts=false --verbose" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

    at Object.EmBj (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:149906:9)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Object.Tbcg (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:251757:15)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.dMKD (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:324399:63)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.mWHM (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:405599:77)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at Module.WXK/ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:271382:65)
    at __webpack_require__ (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:27:30)
    at D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:118:18
    at Object.<anonymous> (D:\Downloads\__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server\express.js:121:10)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1156:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:1000:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:899:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)←[39m
←[90m    at internal/main/run_main_module.js:18:47←[39m
lovell commented 3 years ago

It doesn't look like externals has been configured correctly.

There are plenty of examples of others who have got sharp working with webpack, and most relate to incorrect webpack configuration.

https://github.com/lovell/sharp/search?q=webpack+externals&type=issues

its-dibo commented 3 years ago

I don't have problems with externals, it already execluse node_modules (including sharp) and it generates a .node file in the dist folder, so webpack does it's job.

I think the problem is with process.dlopen

in the output file:

process.dlopen(module, __dirname + "/" + __webpack_require__.p + "sharp.node");

and sharp.node exists in the same output dir

OS: windows 8.1

dependency walker result for the output file sharp.node https://www.mediafire.com/file/osekegnuq9cuzk4/sharp.dwi/file

lovell commented 3 years ago

The initial error message suggests webpack is looking for a file named 33c1e48f049ce3285905e286d212a201.node rather than sharp.node.

D:\Downloads__projects\dev\NodeJs\@eng-dibo\ngx\dist\cms\core\server/33c1e48f049ce3285905e286d212a201.node

Please provide a complete, minimal repo with a package.json and webpack configuration that enables someone else to reproduce this problem.

its-dibo commented 3 years ago

yes, but this file exists.

for clarification: node-loader plugin chnges file name to [hash].[ext]

and the output file searches for it, soit is not the problem @lovell

lovell commented 3 years ago

Please provide a complete, minimal repo with a package.json and webpack configuration that uses externals but does not use node-loader to enable someone else to reproduce this problem.

its-dibo commented 3 years ago

repo: https://github.com/eng-dibo/ngx

the base webpack config file is located in the workspace's root.

the issue occures when you build:server of the project 'cms' to do that, run the following command from the workspace's root.

npm run build:server:dev --prefix projects/cms

additional info: I installed sharp on windows 8 with this cmd:

npm i sharp

I will try the following, may this help

npm install --arch=x64 --platform=linux sharp
lovell commented 3 years ago

It looks like node-loader is still present - https://github.com/eng-dibo/ngx/blob/master/webpack.config.js#L43 - please remove this.

its-dibo commented 3 years ago

additional info:

I installed sharp on windows 8.1 using the following cmd:

npm i sharp

I will try reinstall using

rmdir /s /q node_modules/sharp
npm install --arch=x64 --platform=linux sharp

may it help.

source: https://sharp.pixelplumbing.com/install (windows)

its-dibo commented 3 years ago

removing node-loader causes the error already mentioned above.

https://github.com/lovell/sharp/issues/2517#issuecomment-754901799

its-dibo commented 3 years ago

I will try reinstall using

rmdir /s /q node_modules/sharp
npm install --arch=x64 --platform=linux sharp

may it help.

this didn't help. error: sharp.node is not a valid Win32 application

also npm install --arch=x32 --platform=linux sharp and npm install --arch=x32 sharp didn't help.

lovell commented 3 years ago

Are you using Windows x64 at runtime, or just install time? There are a lot of moving parts here so I will reiterate my plea: please provide a complete, minimal repo with a package.json and webpack configuration that uses externals but does not use node-loader to enable someone else to reproduce this problem.

its-dibo commented 3 years ago

I added webpack config may it help. working in creating a minimal repo with angular project.

its-dibo commented 3 years ago

this issue is specially occures with angular, I just created a brand new angular project and enabled universal app.

minimal reproduction: https://github.com/eng-dibo/ng-sharp-issue

steps to run this reproduction: 1- clone this repo https://github.com/eng-dibo/ng-sharp-issue 2- inatsll packages npm i 3- build the server npm run build:server:dev -> {optional} to build the whole project (browser & server) and serve it npm run start -> the script build:ssr has been renamed to build:server or build:server:dev for clarification.

this generates dist dir contains main.js and sharp-*.node files 4- run the server node dist/main error:

Error:
Something went wrong installing the "sharp" module

node-loader:
Error: The specified module could not be found.
//sharp-ac5709806d227d1d966f7f0b76814d78.node

if we removed node-loader from webpack config, we will get error: Unexpected character '�' (1:2) as mentioned in the detailed "steps of creating this repo" step-by-step below.

steps of creating this reproduction: (for reference)

1- create new angular project:

ng new ngx
ng serve -o //<-- success

2- enable universal app

ng add @nguniversal/express-engine
npm run build:ssr & npm run serve <--success

3- add sharp to server.ts

//server.ts
import * as sharp from "sharp"
sharp('./image.jpg')

npm run build:ssr <-- faild, error: Unexpected character '�' (1:2)

4- use node-loader to load .node file (inside sharp package), we need to use custom webpack to modify webpack configuration in Angular

npm i -D @angular-builders/custom-webpack node-loader ts-loader
//angular.json
{
...
server:{
  "builder": "@angular-builders/custom-webpack:server",
   "options": {
            "customWebpackConfig": {
              "path": "./webpack.server.config.js"
            }
  }
}

}
//webpack.server.config.js (simplified)
module.exports = (config, options) => {
   //remove webpack config from Angular, except 'resolve', and add rules (ts-loader, node-loader)

config = {
    mode: "development",
    resolve: { extensions: [".ts"] },
    entry: { main: ["./server.ts"] },
    target: "node",
    stats: { colors: false },
    module: {
      rules: [
        { test: /\.ts$/, loader: "ts-loader" },
        {
          test: /\.node$/,
          loader: "node-loader",
          options: { name: "[name]-[contenthash].[ext]" }
        }
      ]
    }
  };

return config;

}
npm run build:ssr <-- faild
lovell commented 3 years ago

This sample appears to use node-loader rather than externals. It looks node-loader only copies and renames the node_modules/sharp/build/Release/sharp.node file, ignoring all the other files in node_modules/sharp.

Please can you try using externals as requested.

its-dibo commented 3 years ago

I already use externals, in addition, I already tested building the server with and without node-loader as mentioned above in detailed step-by-step explanation.

both cases cause errors

with node-loader: build command runs successfully, and it generates dist folder contains main.js and sharp-*.node files but the error occures when running node dist/main, because process.dlopen() fails.

without node-loader: build command fails with error: Unexpected character '�' (1:2)

lovell commented 3 years ago

I already use externals

https://github.com/eng-dibo/ng-sharp-issue/search?q=externals returns zero results. Am I missing something?

Applying the following diff appears to work:

--- a/webpack.server.config.js
+++ b/webpack.server.config.js
@@ -7,14 +7,12 @@ module.exports = (config, options) => {
     },
     target: "node",
     stats: { colors: false },
+    externals: {
+      'sharp': 'commonjs sharp',
+    },
     module: {
       rules: [
         { test: /\.ts$/, loader: "ts-loader" },
-        {
-          test: /\.node$/,
-          loader: "node-loader",
-          options: { name: "[name]-[contenthash].[ext]" }
-        }

       ]
     }
   };
its-dibo commented 3 years ago

the issue is probably caused by webpack-node-externals. it faild to add node modules to webpack.resolve.externals, because it resolves the path to 'package.json' file (or node_module) wrongly in case of building the webpack using npm --prefix flag.

I created an issue to mention this problem https://github.com/liady/webpack-node-externals/issues/96

lovell commented 3 years ago

Glad you worked it out, I've added a small section to the docs about the recommend approach that most people use - see https://github.com/lovell/sharp/commit/0dc325daa4a5b15bdbd1d6ff2375e0d18b4380c7

nph278 commented 3 years ago

I'm not using webpack, and I'm still having this problem. I have: sharp: 0.26.2 OS: macOS 11.0.1 (Not M1) Node: 14.15.5 npm: 7.5.4

 Something went wrong installing the "sharp" module

 Cannot find module '../build/Release/sharp.node'
lovell commented 3 years ago

@nph278 Please open a new installation issue and answer all of the questions - https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md

scookdev commented 2 years ago

What fixed it for me was upgrading to sharp version 0.30.1.

matvejs16 commented 1 year ago

To help other people figure this out. In webpack.config.js

externals: ['node_modules', 'sharp']

This will not work, and you will get error:

ReferenceError: sharp is not defined

Only this will help (at least in my case)

externals: ['node_modules', {
    'sharp': 'commonjs sharp'
}]

I hope I was helpful for someone