Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node:18-alpine build failing for canvas install #2086

Open
sabreu-teknorix opened this issue May 23, 2024 · 8 comments
Open

node:18-alpine build failing for canvas install #2086

sabreu-teknorix opened this issue May 23, 2024 · 8 comments

Comments

@sabreu-teknorix
Copy link

Environment

  • Platform: Bitbucket pipeline
  • Docker Version: N/A
  • Node.js Version: 18.20.3
  • Image Tag: 18-alpine

Expected Behavior

build should not fail

Current Behavior

Build failing with stack trace

.../[email protected]/node_modules/canvas install: Traceback (most recent call last):
.../[email protected]/node_modules/canvas install: File "/root/.cache/node/corepack/v1/pnpm/8.15.7/dist/node_modules/node-gyp/gyp/gyp_main.py", line 42, in
.../[email protected]/node_modules/canvas install: import gyp # noqa: E402
.../[email protected]/node_modules/canvas install: ^^^^^^^^^^
.../[email protected]/node_modules/canvas install: File "/root/.cache/node/corepack/v1/pnpm/8.15.7/dist/node_modules/node-gyp/gyp/pylib/gyp/init.py", line 9, in
.../[email protected]/node_modules/canvas install: import gyp.input
.../[email protected]/node_modules/canvas install: File "/root/.cache/node/corepack/v1/pnpm/8.15.7/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in
.../[email protected]/node_modules/canvas install: from distutils.version import StrictVersion
.../[email protected]/node_modules/canvas install: ModuleNotFoundError: No module named 'distutils'
.../[email protected]/node_modules/canvas install: gyp ERR! configure error
.../[email protected]/node_modules/canvas install: gyp ERR! stack Error: gyp failed with exit code: 1
.../[email protected]/node_modules/canvas install: gyp ERR! stack at ChildProcess.onCpExit (/root/.cache/node/corepack/v1/pnpm/8.15.7/dist/node_modules/node-gyp/lib/configure.js:325:16)
.../[email protected]/node_modules/canvas install: gyp ERR! stack at ChildProcess.emit (node:events:517:28)
.../[email protected]/node_modules/canvas install: gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:292:12)
.../[email protected]/node_modules/canvas install: gyp ERR! System Linux 5.15.0-1058-aws
.../[email protected]/node_modules/canvas install: gyp ERR! command "/usr/local/bin/node" "/root/.cache/node/corepack/v1/pnpm/8.15.7/dist/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--update-binary" "--module=/app/node_modules/.pnpm/[email protected]/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/app/node_modules/.pnpm/[email protected]/node_modules/canvas/build/Release" "--napi_version=9" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v108"
.../[email protected]/node_modules/canvas install: gyp ERR! cwd /app/node_modules/.pnpm/[email protected]/node_modules/canvas
.../[email protected]/node_modules/canvas install: gyp ERR! node -v v18.20.3
.../[email protected]/node_modules/canvas install: gyp ERR! node-gyp -v v9.4.1
.../[email protected]/node_modules/canvas install: gyp ERR! not ok

Possible Solution

Steps to Reproduce

Additional Information

@LaurentGoderre
Copy link
Member

LaurentGoderre commented May 23, 2024

Your issue is a combination of Automattic/node-canvas#2158 and Automattic/node-canvas#1065.

The following works

FROM node:18-alpine

WORKDIR /home/node

RUN set -ex; \
    apk add --no-cache --virtual .gyp \
        # Gyp build dependencies
        python3 make g++ \
        # Canvas build dependencies
        pixman-dev cairo-dev pango-dev pkgconfig; \
    npm install canvas; \
    apk del .gyp

@maxime-gd
Copy link

This solution didn't work for me but I found a way to get it to work. Docker updated Alpine yesterday and reverse my dockerfile to the previous one worked : lts-alpine3.19 for Node 20 or 18-alpine3.19 for Node 18.

@LaurentGoderre
Copy link
Member

@maxime-gd what error do you have? It worked for me for both alpine 3.19 and 3.20

@alex-statsig
Copy link

Ran into the same distutils issue in a different project, had to revert to alpine3.19 to fix.

I think maybe the python version was updated in alpine3.20 (to 3.12) and thus distutils is no longer available by default, so something like pip3 install setuptools would be required to fix. Haven't gotten this working fully yet though.

@maxime-gd
Copy link

The same one as @sabreu-teknorix and @alex-statsig : distutils missing.

@SystemParadox
Copy link

The issue is this: nodejs/node-gyp#2869 and affects node:20-alpine and probably others as well. This is not just a canvas issue, it affects all node-gyp builds.

apk add py-setuptools appears to fix it.

@LaurentGoderre
Copy link
Member

Maybe we need to append the docs about building native deps to document this

@LaurentGoderre
Copy link
Member

PR to update the docs: #2099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants