'virtual:world' 所需的程序包 'cairo',未找到

Package 'cairo', required by 'virtual:world', not found

我在容器中使用 alpine linux。前一段时间我遇到了与 Package cairo was not found in the pkg-config search path. Node j.s install canvas issue 相同的错误,我将以下代码片段添加到我的 Dockerfile 中:

    # Install cairo for one of our frontend dependencies
RUN apk add --update --no-cache cairo \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

这使错误消失了(至少根据我的记忆,已经几个月了)。

今天 运行 docker-compose exec web yarn watch 时再次出现此错误。这是错误的完整输出:

[4/4] Building fresh packages...
success Installed "node-gyp@3.8.0" with binaries:
[1/2] ⠠ canvas
warning Error running install script for optional dependency: "/var/www/html/node_modules/canvas: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /var/www/html/node_modules/canvas
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@8.14.0 | linux | x64
gyp http GET https://nodejs.org/download/release/v8.14.0/node-v8.14.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v8.14.0/node-v8.14.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v8.14.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v8.14.0/SHASUMS256.txt
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/usr/local/share/.config/yarn/global/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/var/www/html/node_modules/canvas/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/share/.config/yarn/global/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/8.14.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.14.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/share/.config/yarn/global/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.14.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/var/www/html/node_modules/canvas',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
Package 'cairo', required by 'virtual:world', not found
gyp: Call to './util/has_lib.sh freetype' returned exit status 0 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/share/.config/yarn/global/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command \"/usr/bin/node\" \"/usr/local/bin/node-gyp\" \"rebuild\"
gyp ERR! cwd /var/www/html/node_modules/canvas
gyp ERR! node -v v8.14.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok"
Done in 98.27s.

我可以证明开罗在集装箱上:

WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
cairo-1.14.12-r2 description:
A vector graphics library

cairo-1.14.12-r2 webpage:
http://cairographics.org/

cairo-1.14.12-r2 installed size:
1097728

cairo-1.14.12-r2 depends on:
so:libX11.so.6
so:libXext.so.6
so:libXrender.so.1
so:libc.musl-x86_64.so.1
so:libfontconfig.so.1
so:libfreetype.so.6
so:libpixman-1.so.0
so:libpng16.so.16
so:libxcb-render.so.0
so:libxcb-shm.so.0
so:libxcb.so.1
so:libz.so.1

cairo-1.14.12-r2 provides:
so:libcairo-script-interpreter.so.2=2.11400.12
so:libcairo.so.2=2.11400.12

cairo-1.14.12-r2 is required by:

cairo-1.14.12-r2 contains:
usr/lib/libcairo.so.2.11400.12
usr/lib/libcairo-script-interpreter.so.2
usr/lib/libcairo-script-interpreter.so.2.11400.12
usr/lib/libcairo.so.2
usr/lib/cairo/cairo-sphinx.so.0
usr/lib/cairo/cairo-fdr.so.0
usr/lib/cairo/cairo-fdr.so
usr/lib/cairo/cairo-fdr.so.0.0.0
usr/lib/cairo/cairo-sphinx.so
usr/lib/cairo/cairo-sphinx.so.0.0.0

cairo-1.14.12-r2 triggers:

cairo-1.14.12-r2 has auto-install rule:

cairo-1.14.12-r2 affects auto-installation of:

cairo-1.14.12-r2 replaces:

cairo-1.14.12-r2 license:
LGPL-2.0-or-later MPL-1.1

我在浏览后没有在任何地方看到任何 cairo.pc 文件,那么我如何确定我需要采取什么步骤来让我的 yarn install 了解开罗的位置?

这可以通过安装 cairo-dev 软件包轻松解决。

根据Alpine的包搜索,它会在/usr/lib/pkgconfig下安装cairo.pc,很可能被gyp检测到:

https://pkgs.alpinelinux.org/contents?file=cairo.pc&path=&name=&branch=v3.8