npm install sharp failed due to libvips download failure

created at 05-31-2022 views: 45

Today, I want to write a tool to restore the atlas packaged by laya to the original thumbnail. I need to use sharp, so I tap it with my little hand~

npm i sharp -S

Hey, the following error occurred:

413 error code 1
414 error path F:\tgit\fy\break-atlas\node_modules\sharp
415 error command failed
416 error command C:\WINDOWS\system32\cmd.exe /d /s /c (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
417 error sharp: Downloading https://npm.taobao.org/mirrors/sharp-libvips/v8.10.6/libvips-8.10.6-win32-x64.tar.gz
417 error sharp: Attempting to build from source via node-gyp but this may fail due to the above error
417 error sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
417 error �ڴ˽��������һ������һ����Ŀ����Ҫ���ò������ɣ������ӡ�/m�����ء�
417 error   nothing.c
417 error   win_delay_load_hook.cc
417 error   nothing.vcxproj -> F:\tgit\fy\break-atlas\node_modules\sharp\build\Release\\nothing.lib
417 error   VError.cpp
417 error ..\src\libvips\cplusplus\VError.cpp(33): fatal error C1083: Cannot open include file: 'vips/intl.h': No such file or directory [F:\tgit\fy\break-atlas\node_modules\sharp\build\libvips-cpp.vcxproj]
418 error sharp: Installation error: tunneling socket could not be established, cause=socket hang up
418 error gyp info it worked if it ends with ok
418 error gyp info using node-gyp@7.1.2
418 error gyp info using node@10.14.2 | win32 | x64
418 error gyp info find Python using Python version 2.7.0 found at "C:\Python27\python.exe"
418 error gyp info find VS using VS2015 (14.0) found at:
418 error gyp info find VS "D:\Program Files (x86)\Microsoft Visual Studio 14.0"
418 error gyp info find VS run with --verbose for detailed information
418 error gyp info spawn C:\Python27\python.exe
418 error gyp info spawn args [ 'C:\\Users\\fygame\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
418 error gyp info spawn args   'binding.gyp',
418 error gyp info spawn args   '-f',
418 error gyp info spawn args   'msvs',
418 error gyp info spawn args   '-I',
418 error gyp info spawn args   'F:\\tgit\\fy\\break-atlas\\node_modules\\sharp\\build\\config.gypi',
418 error gyp info spawn args   '-I',
418 error gyp info spawn args   'C:\\Users\\fygame\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
418 error gyp info spawn args   '-I',
418 error gyp info spawn args   'C:\\Users\\fygame\\AppData\\Local\\node-gyp\\Cache\\10.14.2\\include\\node\\common.gypi',
418 error gyp info spawn args   '-Dlibrary=shared_library',
418 error gyp info spawn args   '-Dvisibility=default',
418 error gyp info spawn args   '-Dnode_root_dir=C:\\Users\\fygame\\AppData\\Local\\node-gyp\\Cache\\10.14.2',
418 error gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\fygame\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp',
418 error gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\fygame\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\10.14.2\\\\<(target_arch)\\\\node.lib',
418 error gyp info spawn args   '-Dmodule_root_dir=F:\\tgit\\fy\\break-atlas\\node_modules\\sharp',
418 error gyp info spawn args   '-Dnode_engine=v8',
418 error gyp info spawn args   '--depth=.',
418 error gyp info spawn args    '--no-parallel',
418 error gyp info spawn args   '--generator-output',
418 error gyp info spawn args   'F:\\tgit\\fy\\break-atlas\\node_modules\\sharp\\build',
418 error gyp info spawn args   '-Goutput_dir=.' ]
418 error gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe
418 error gyp info spawn args [ 'build/binding.sln',
418 error gyp info spawn args   '/clp:Verbosity=minimal',
418 error gyp info spawn args   '/nologo',
418 error gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
418 error gyp ERR! build error
418 error gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1
418 error gyp ERR! stack     at ChildProcess.onExit (C:\Users\fygame\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
418 error gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
418 error gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
418 error gyp ERR! System Windows_NT 10.0.19041
418 error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\fygame\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
418 error gyp ERR! cwd F:\tgit\fy\break-atlas\node_modules\sharp
418 error gyp ERR! node -v v10.14.2
418 error gyp ERR! node-gyp -v v7.1.2
418 error gyp ERR! not ok
419 verbose exit 1

As you can see from the error message, sharp depends on libvips, it will download first https://npm.taobao.org/mirrors/sharp-libvips/v8.10.6/libvips-8.10.6-win32-x64 .tar.gz, then compile

And the next error is

..\src\libvips\cplusplus\VError.cpp(33): fatal error C1083: Cannot open include file: 'vips/intl.h': No such file or directory

It can be speculated that the download of the compressed package of the sharp-libvips above failed.

Go to the npm cache directory to view the _libvips directory during installation, it is indeed empty. The compressed package can be successfully downloaded using a browser. So the solution is much simpler, just put the manually downloaded compressed package into the cache directory and reinstall it.

You can view your npm cache directory with the following command:

npm config get cache

My cache directory is C:\Users\fygame\AppData\Local\npm-cache, so put libvips-8.10.6-win32-x64.tar.gz into C:\Users\fygame\AppData\Local\npm-cache\_libvips, re-execute npm i sharp -S successfully.

F:\tgit\fy\break-atlas>npm i sharp --unsafe-perm
(node:171408) ExperimentalWarning: The fs.promises API is experimental

added 69 packages, and audited 75 packages in 37s

6 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

F:\tgit\fy\break-atlas>npm i sharp
(node:173888) ExperimentalWarning: The fs.promises API is experimental

up to date, audited 75 packages in 2s

6 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
created at:05-31-2022
edited at: 05-31-2022: