新下载了个项目模板,安装包就遇到了各种各样问题
电脑:mac
使用npm i 等命令一直安装项目,然后一直报错
2534 info run canvas@2.11.2 install node_modules/canvas node-pre-gyp install --fallback-to-build --update-binary
2535 info run sharp@0.32.6 install node_modules/sharp (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
2536 info run sharp@0.32.6 install { code: 1, signal: null }
2537 timing reify:rollback:createSparse Completed in 4602ms
2538 timing reify:rollback:retireShallow Completed in 0ms
2539 timing command:install Completed in 41771ms
2540 verbose stack Error: command failed
2540 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:63:27)
2540 verbose stack at ChildProcess.emit (node:events:513:28)
2540 verbose stack at maybeClose (node:internal/child_process:1093:16)
2540 verbose stack at Socket.<anonymous> (node:internal/child_process:451:11)
2540 verbose stack at Socket.emit (node:events:513:28)
2540 verbose stack at Pipe.<anonymous> (node:net:757:14)
2541 verbose pkgid sharp@0.32.6
2542 verbose cwd /Users/apple/Desktop/公司/jhtt-new/link-we-chat-front/vue3-lw-pc
2543 verbose Darwin 20.3.0
2544 verbose node v16.17.0
2545 verbose npm v8.15.0
2546 error code 1
2547 error path /Users/apple/Desktop/公司/jhtt-new/link-we-chat-front/vue3-lw-pc/node_modules/sharp
2548 error command failed
2549 error command sh /var/folders/9c/hdh5sy1x1vd8qp5l4939z_zr0000gn/T/install-7bd83f7d.sh
2550 error sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.14.5/libvips-8.14.5-darwin-x64.tar.br
2550 error sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
2551 error sharp: Installation error: socket hang up
我百度了关于npm安装sharp失败/canvas失败的解决办法,改了 .npmrc文件的镜像
registry=https://registry.npmmirror.comdisturl=https://registry.npmmirror.com/-/binary/node/
# node-sass预编译二进制文件下载地址
sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass
# sharp预编译共享库, 截止2022-09-20 sharp@0.31.0的预编译共享库并未同步到镜像, 入安装失败可切换到sharp@0.30.7使用
sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips
python_mirror=https://registry.npmmirror.com/-/binary/python/
electron_mirror=https://registry.npmmirror.com/-/binary/electron/
electron_builder_binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
# 无特殊配置参考{pkg-name}_binary_host_mirror={mirror}
canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas
node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3
better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3
但是依旧没起效果.
最后我改变了思路:安装了yarn
npm i yarn -g
使用 yarn 进行安装,但是又出来另一个错误
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]CC(target) Release/obj.target/nothing/../node-addon-api/nothing.oLIBTOOL-STATIC Release/nothing.a
warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)TOUCH Release/obj.target/libvips-cpp.stampCXX(target) Release/obj.target/sharp-darwin-x64/src/common.o
../src/common.cc:13:10: fatal error: 'vips/vips8' file not found
#include <vips/vips8>^~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/sharp-darwin-x64/src/common.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (node:events:513:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 20.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/apple/Desktop/公司/jhtt-new/link-we-chat-front/vue3-lw-pc/node_modules/sharp
找到了这篇文章
npm安装sharp出现的问题(安装失败的问题及解决)_npm sharp-CSDN博客
使用了两行命令成功了:
npm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
npm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"