新下載了個項目模板,安裝包就遇到了各種各樣問題
電腦: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"