Search code examples
node.jsdockernode-gyp

Node docker build fails for node-gyp rebuild


Building docker image for ts node js app, after adding "@kafkajs/zstd": "^0.1.1" to package.json, docker build started to fail. Here is docker file

# .......Development Stage.......
FROM --platform=linux/amd64 node:18-alpine3.18 as development

WORKDIR /home/app
COPY . /home/app

# RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*

RUN npm install
RUN npm run build

EXPOSE 8080

CMD ["node", "/home/app/dist/main.js"]

And here is the error:

#9 71.27 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use

Looked at that thread here, and that thread here . tried to add python to docker file:

# RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* or

RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm install \
    && apk del .gyp

After that build still fails with:

#10 83.53 npm ERR! code 1
#10 83.53 npm ERR! path /usr/src/server/node_modules/segfault-handler
#10 83.55 npm ERR! command failed
#10 83.55 npm ERR! command sh -c node-gyp rebuild
#10 83.55 npm ERR! make: Entering directory '/usr/src/server/node_modules/segfault-handler/build'
#10 83.55 npm ERR!   CXX(target) Release/obj.target/segfault-handler/src/segfault-handler.o
#10 83.55 npm ERR! make: Leaving directory '/usr/src/server/node_modules/segfault-handler/build'
#10 83.55 npm ERR! gyp info it worked if it ends with ok
#10 83.56 npm ERR! gyp info using [email protected]
#10 83.56 npm ERR! gyp info using [email protected] | linux | x64
#10 83.56 npm ERR! gyp info find Python using Python version 3.8.15 found at "/usr/bin/python3"
#10 83.56 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.8.0/node-v16.8.0-headers.tar.gz
#10 83.56 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.8.0/node-v16.8.0-headers.tar.gz
#10 83.56 npm ERR! gyp http GET https://unofficial-builds.nodejs.org/download/release/v16.8.0/SHASUMS256.txt
#10 83.56 npm ERR! gyp http 200 https://unofficial-builds.nodejs.org/download/release/v16.8.0/SHASUMS256.txt
#10 83.56 npm ERR! (node:62) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
#10 83.56 npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
#10 83.56 npm ERR! gyp info spawn make
#10 83.56 npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
#10 83.56 npm ERR! ../src/segfault-handler.cpp:23:10: fatal error: execinfo.h: No such file or directory
#10 83.56 npm ERR!    23 | #include <execinfo.h>
#10 83.56 npm ERR!       |          ^~~~~~~~~~~~
#10 83.56 npm ERR! compilation terminated.
#10 83.56 npm ERR! make: *** [segfault-handler.target.mk:117: Release/obj.target/segfault-handler/src/segfault-handler.o] Error 1
#10 83.56 npm ERR! gyp ERR! build error 
#10 83.56 npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
#10 83.56 npm ERR! gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
#10 83.56 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
#10 83.56 npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
#10 83.56 npm ERR! gyp ERR! System Linux 5.10.124-linuxkit
#10 83.56 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#10 83.56 npm ERR! gyp ERR! cwd /usr/src/server/node_modules/segfault-handler
#10 83.56 npm ERR! gyp ERR! node -v v16.8.0
#10 83.56 npm ERR! gyp ERR! node-gyp -v v7.1.2
#10 83.56 npm ERR! gyp ERR! not ok

After that read this thread https://github.com/ddopson/node-segfault-handler/issues/70, but also not much luck, perhaps Im digging to deep, any help appreciated , thanks!


Solution

  • The thread you mention provides a clue for how this can be done. But it looks like you need to roll back to an earlier version of Node.

    FROM --platform=linux/amd64 node:15.14.0-alpine3.13 as development
    
    WORKDIR /home/app
    COPY package.json /home/app
    
    RUN apk add --no-cache --no-progress \
            python3 \
            make \
            g++ \
            libexecinfo-dev \
            libexecinfo
    
    RUN npm install
    

    Assuming a simple package.json like this:

    {
      "name": "test",
      "version": "1.0.0",
      "dependencies": {
        "@kafkajs/zstd": "^0.1.1"
      }
    }