执行npm install安装依赖时sharp包请求超时报错求助
npm ERR! code 1
npm ERR! path C:\Users\HP\Desktop\workings\alx-files_manager\node_modules\sharp
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
npm ERR! sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.12.2/libvips-8.12.2-win32-x64.tar.br
npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
npm ERR! sharp: Installation error: Request timed out
npm ERR! A complete log of this run can be found in: C:\Users\HP\AppData\Local\npm-cache_logs\2024-03-12T17_05_23_036Z-debug-0.log
以下是可行的解决方法:
清理npm缓存后重试
先清理缓存,再重新执行安装命令:npm cache clean --force npm install使用国内镜像源加速下载
临时切换npm镜像为国内源,再执行安装:npm config set registry https://registry.npmmirror.com/ npm config set sharp_binary_host https://npmmirror.com/mirrors/sharp npm config set sharp_libvips_binary_host https://npmmirror.com/mirrors/sharp-libvips npm install安装完成后如需恢复原镜像,执行:
npm config delete registry npm config delete sharp_binary_host npm config delete sharp_libvips_binary_host手动下载libvips并指定路径
- 手动下载报错中提到的v8.12.2-win32-x64版本libvips压缩包
- 解压到本地任意路径,比如
C:\libvips - 设置环境变量后执行安装:
set SHARP_LIBVIPS_DIRECTORY=C:\libvips npm install检查网络环境
- 关闭正在运行的代理工具
- 切换到稳定的有线网络或更换网络环境后重试安装
内容的提问来源于stack exchange,提问作者Time flies

