libvips下载失败导致npm安装sharp失败

2021-04-29  本文已影响0人  taiyosen

今天想写个工具将laya打包出来的图集还原成原始的小图,需要用到sharp,于是小手敲起来~

npm i sharp -S

咦,出现了以下错误:

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

从错误信息可以看出,sharp依赖于libvips,他会先下载https://npm.taobao.org/mirrors/sharp-libvips/v8.10.6/libvips-8.10.6-win32-x64.tar.gz,然后进行编译,而接下去的报错是..\src\libvips\cplusplus\VError.cpp(33): fatal error C1083: Cannot open include file: 'vips/intl.h': No such file or directory,可以推测上面那个sharp-libvips的压缩包下载失败。去npm cache目录查看安装时的_libvips目录,果然是空的。而使用浏览器可以成功下载这个压缩包。于是解决办法简单多了,把手动下载的压缩包放到cache目录里再重新安装就好了。
使用以下命令可以查看自己的npm cache目录:

npm config get cache

我的cache目录是C:\Users\fygame\AppData\Local\npm-cache,于是把libvips-8.10.6-win32-x64.tar.gz放入C:\Users\fygame\AppData\Local\npm-cache\_libvips,重新执行npm i sharp -S成功。

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
上一篇 下一篇

猜你喜欢

热点阅读