'node canvas not installing on docker

can anyone help me to figure out this error? so I'm doing node version upgrade and dockerization tasks. we used node js 8.15.1 before now we want to update it to node js 16.15.0 the project was working on node 8.15.1 but when I tried to run npm install with node js 16.15.0 it got me node canvas error as below

npm ERR! code 1
npm ERR! path /app/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! make: Entering directory '/app/node_modules/canvas/build'
npm ERR!   SOLINK_MODULE(target) Release/obj.target/canvas-postbuild.node
npm ERR!   COPY Release/canvas-postbuild.node
npm ERR!   CXX(target) Release/obj.target/canvas/src/Canvas.o
npm ERR! make: Leaving directory '/app/node_modules/canvas/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 2.7.16 found at "/usr/bin/python"
npm ERR! gyp http GET https://nodejs.org/download/release/v16.15.0/node-v16.15.0-headers.tar.gz
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.15.0/node-v16.15.0-headers.tar.gz
npm ERR! gyp http GET https://nodejs.org/download/release/v16.15.0/SHASUMS256.txt
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.15.0/SHASUMS256.txt
npm ERR! (node:19) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /usr/bin/python
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/app/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/app/node_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/app/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/root/.cache/node-gyp/16.15.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/16.15.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/app/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/16.15.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/app/node_modules/canvas',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
... // C++ build log
npm ERR!                                             ^~~~~~~~
npm ERR! /root/.cache/node-gyp/16.15.0/include/node/v8.h:3060:44: note:   candidate expects 1 argument, 0 provided
npm ERR! make: *** [canvas.target.mk:149: Release/obj.target/canvas/src/Canvas.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/app/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Linux 5.4.0-107-generic
npm ERR! gyp ERR! command "/usr/local/bin/node" "/app/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /app/node_modules/canvas
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-13T07_10_55_542Z-debug-0.log
The command '/bin/sh -c npm install node-libcurl --build-from-source' returned a non-zero code: 1

Here is my Dockerfile

FROM node:16.15.0
WORKDIR /app
COPY package*.json ./
RUN apt-get update && apt-get install -qq build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev g++ software-properties-common 
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt install python3.7 -y
RUN npm config set python /usr/bin/python
RUN npm install -g node-gyp
RUN npm i -g node-pre-gyp
RUN npm install node-libcurl --build-from-source
RUN npm i [email protected] 
RUN npm install -d
COPY . .
EXPOSE 3000
CMD ["npm","start"]

so my issue is every time I try to build this container using docker build -t qr . it got me the above error. can anyone tell me why I keep getting this error and how can I resolve this. thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source