node使用canvas

2023/2/21 canvas
1/1] scripts.install canvas@latest run "node-pre-gyp install --fallback-to-build --update-binary", root: "/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas"
node-pre-gyp http GET https://cdn.npmmirror.com/binaries/canvas/v2.11.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://cdn.npmmirror.com/binaries/canvas/v2.11.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz 
node-pre-gyp WARN Pre-built binaries not installable for canvas@2.11.0 and node@16.18.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error response status 404 Not Found on https://cdn.npmmirror.com/binaries/canvas/v2.11.0/canvas-v2.11.0-node-v93-darwin-unknown-arm64.tar.gz 
/bin/sh: pkg-config: command not found
gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:284:16)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Darwin 22.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
gyp ERR! cwd /Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas
gyp ERR! node -v v16.18.0
gyp ERR! node-gyp -v v9.1.0
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/a9374/myProject/wdAPI/node_modules/_@mapbox_node-pre-gyp@1.0.10@@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1100:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
node-pre-gyp ERR! System Darwin 22.2.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--update-binary"
node-pre-gyp ERR! cwd /Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas
node-pre-gyp ERR! node -v v16.18.0
node-pre-gyp ERR! node-pre-gyp -v v1.0.10
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --update-binary --module=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/a9374/myProject/wdAPI/node_modules/_canvas@2.11.0@canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
[npminstall:runscript:error] canvas@latest scripts.install run "node-pre-gyp install --fallback-to-build --update-binary" error: Error [RunScriptError]: Run "sh -c node-pre-gyp install --fallback-to-build --update-binary" error, exit code 1
    at ChildProcess.<anonymous> (/Users/a9374/.npm-global/lib/node_modules/cnpm/node_modules/runscript/index.js:96:21)
    at ChildProcess.emit (node:events:513:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12) {
  stdio: [Object],
  exitcode: 1
}
✖ Install fail! RunScriptError: post install error, please remove node_modules before retry!
Run "sh -c node-pre-gyp install --fallback-to-build --update-binary" error, exit code 1
RunScriptError: Run "sh -c node-pre-gyp install --fallback-to-build --update-binary" error, exit code 1
    at ChildProcess.<anonymous> (/Users/a9374/.npm-global/lib/node_modules/cnpm/node_modules/runscript/index.js:96:21)
    at ChildProcess.emit (node:events:513:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)
npminstall version: 6.5.2
npminstall args: /usr/local/bin/node /Users/a9374/.npm-global/lib/node_modules/cnpm/node_modules/npminstall/bin/install.js --fix-bug-versions --china --userconfig=/Users/a9374/.cnpmrc --disturl=https://npmmirror.com/mirrors/node --registry=https://registry.npmmirror.com canvas --unsafe-perm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

# 尝试 --unsafe

失败

项目终端中输入 sudo cnpm install canvas --unsafe-perm

参考: node安装依赖包时 node-pre-gyp 报错解决办法 (opens new window)

# 尝试 安装环境

终端内输入:brew install pkg-config cairo pango libpng jpeg giflib librsvg

参考: 让你在node服务中轻松使用canvas (opens new window) node-canvas 安装攻略 (opens new window)

系统 命令
mac brew install pkg-config cairo pango libpng jpeg giflib librsvg
Ubuntu sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
Fedora sudo yum install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel
Solaris pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto
OpenBSD doas pkg_add cairo pango png jpeg giflib
最后更新时间: 2023/2/23 18:24:24