解决 npm i sharp@0.23.4 安装失败异常 npm install sharp异常解决
解决 npm i sharp@0.23.4 安装失败异常 npm install sharp异常解决
- 解决 npm i sharp@0.23.4 安装失败异常 npm install sharp异常解决
解决 npm i sharp@0.23.4 安装失败异常 npm install sharp异常解决
本地环境:node: 12.20.1
异常提示关键字:Python、C++编译问题
info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-win32-x64.tar.gz
ERR! sharp Prebuilt libvips binaries are not yet available for win32-x64
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependenciesD:\java-works\yzwl\temp\node_modules\sharp>if not defined npm_config_node_gyp (node "D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2022
gyp ERR! find VS running in VS Command Prompt, installation path is:
gyp ERR! find VS "D:\apps\Microsoft\VisualStudio"
gyp ERR! find VS - will only use this version
gyp ERR! find VS unknown version "undefined" found at "D:\apps\Microsoft\VisualStudio"
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - found in "D:\Program Files (x86)\Microsoft Visual Studio 14.0"
gyp ERR! find VS - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS msvs_version does not match this VS Command Prompt or the
gyp ERR! find VS installation cannot be used.
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack at D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack at D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack at D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack at D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack at D:\apps\nvm\v12.20.1\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack at ChildProcess.exithandler (child_process.js:315:5)
gyp ERR! stack at ChildProcess.emit (events.js:314:20)
gyp ERR! stack at maybeClose (internal/child_process.js:1022:16)
gyp ERR! System Windows_NT 10.0.22631
gyp ERR! command "D:\\apps\\nvm\\nodejs\\node.exe" "D:\\apps\\nvm\\v12.20.1\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\java-works\yzwl\temp\node_modules\sharp
gyp ERR! node -v v12.20.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN temp@1.0.0 No description
npm WARN temp@1.0.0 No repository field.npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sharp@0.23.4 install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sharp@0.23.4 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
这个异常就是因为 sharp依赖于_libvips编译模块,需要调用编译模块之后才能安装sharp,但是npm下载和编译失败了,需要手动将预编译的二进制文件下载下来放到本地npm缓存路径当中
Sharp版本0.23.4对应的libvips下载地址: libvips-8.8.1-win32-x64.tar.gz
默认的NPM缓存路径:C:\Users\用户\AppData\Roaming\npm-cache\_libvips
npm-cache\_libvips
是用于存放预编译的二进制文件缓存路径
通过CMD查询具体本机的NPM缓存路径:
# 查看当前 npm 缓存路径
npm config get cache
最后执行安装sharp查看是否成功
npm i sharp@0.23.4