Skip to content

Latest docker build breaks node-gyp in node-18 #2009

Description

@wbecker

Environment

  • Platform:
  • Docker Version:
  • Node.js Version:
  • Image Tag: 18-alpine

(This happens inside my managed CI provider, not sure on its version)

Current Behavior

When I install sharp, it fails due to node gyp:

Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: /usr/app/node_modules/cpu-features
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@10.0.1
gyp info using node@18.19.0 | linux | x64
gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if \"python3\" can be used
gyp ERR! find Python - executable path is \"\"
gyp ERR! find Python - \"\" could not be run
gyp ERR! find Python checking if \"python\" can be used
gyp ERR! find Python - executable path is \"\"
gyp ERR! find Python - \"\" could not be run
gyp ERR! find Python 
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python=\"/path/to/pythonexecutable\"
gyp ERR! find Python (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python npm config set python \"/path/to/pythonexecutable\"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python 
gyp ERR! configure error 
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:306:11)
gyp ERR! stack at PythonFinder.findPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:164:17)
gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
gyp ERR! stack at async configure (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:23:18)
gyp ERR! stack at async run (/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js:81:18)
gyp ERR! System Linux 6.2.0-1015-aws
gyp ERR! command \"/usr/local/bin/node\" \"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\"
gyp ERR! cwd /usr/app/node_modules/cpu-features
gyp ERR! node -v v18.19.0
gyp ERR! node-gyp -v v10.0.1
gyp ERR! not ok"
2023-12-12 14:02:50
info This module is OPTIONAL, you can safely ignore this error
2023-12-12 14:02:50
error /usr/app/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /usr/app/node_modules/sharp
Output:
sharp: Installation error: Invalid Version: 1.2.4_git20230717
sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies

This was working yesterday and seems to coincide with this build going live:

When I stick my docker version to the node:18-alpine3.18 it works again.

Activity

  1. wbecker commented on Dec 12, 2023

    @wbecker
    Author

    Is it somehow missing python from the install?

  2. louiswebdev commented on Dec 12, 2023

    @louiswebdev

    We had the latest node:18-alpine image (now pointing to node:18-alpine3.19 instead of node:18-alpine3.18) segfault and had to hardcode not to use the 18-alpine tag but specifically the alpine3.18 based one.

    Maybe related?

  3. louiswebdev commented on Dec 12, 2023

    @louiswebdev

    I can't be very specific publicly, but two of our use cases using the alpine3.19 based node:18 image always exited with exit code: 139

  4. ThallesP commented on Dec 12, 2023

    @ThallesP

    Had same issues with Sharp too, maybe some compilation libraries (libc, musl) are outdated or updated?

    #0 61.63 npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
    #0 61.63 npm ERR! ../src/pipeline.cc: In member function 'virtual void PipelineWorker::OnOK()':
    #0 61.63 npm ERR! ../src/pipeline.cc:1229:30: error: aggregate 'PipelineWorker::OnOK()::stat64 st' has incomplete type and cannot be defined
    #0 61.63 npm ERR!  1229 |         struct STAT64_STRUCT st;
    #0 61.63 npm ERR!       |                              ^~
    #0 61.63 npm ERR! ../src/pipeline.cc:1230:55: error: invalid use of incomplete type 'struct PipelineWorker::OnOK()::stat64'
    #0 61.63 npm ERR!  1230 |         if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
    #0 61.63 npm ERR!       |                                                       ^
    #0 61.63 npm ERR! ../src/pipeline.cc:44:23: note: forward declaration of 'struct PipelineWorker::OnOK()::stat64'
    #0 61.63 npm ERR!    44 | #define STAT64_STRUCT stat64
    #0 61.63 npm ERR!       |                       ^~~~~~
    #0 61.63 npm ERR! ../src/pipeline.cc:1229:16: note: in expansion of macro 'STAT64_STRUCT'
    #0 61.63 npm ERR!  1229 |         struct STAT64_STRUCT st;
    #0 61.63 npm ERR!       |                ^~~~~~~~~~~~~
    #0 61.63 npm ERR! make: *** [sharp-linuxmusl-x64.target.mk:167: Release/obj.target/sharp-linuxmusl-x64/src/pipeline.o] Error 1
    

    Is there any version I can downgrade for now? I can't get the specific tag, but it seems to be this digest which was working for me: 4bdb3f3105718f0742bc8d64bb4e36e8f955ebbee295325e40ae80bc8ef78833

  5. ThallesP commented on Dec 12, 2023

    @ThallesP

    Had same issues with Sharp too, maybe some compilation libraries (libc, musl) are outdated or updated?

    #0 61.63 npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
    #0 61.63 npm ERR! ../src/pipeline.cc: In member function 'virtual void PipelineWorker::OnOK()':
    #0 61.63 npm ERR! ../src/pipeline.cc:1229:30: error: aggregate 'PipelineWorker::OnOK()::stat64 st' has incomplete type and cannot be defined
    #0 61.63 npm ERR!  1229 |         struct STAT64_STRUCT st;
    #0 61.63 npm ERR!       |                              ^~
    #0 61.63 npm ERR! ../src/pipeline.cc:1230:55: error: invalid use of incomplete type 'struct PipelineWorker::OnOK()::stat64'
    #0 61.63 npm ERR!  1230 |         if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
    #0 61.63 npm ERR!       |                                                       ^
    #0 61.63 npm ERR! ../src/pipeline.cc:44:23: note: forward declaration of 'struct PipelineWorker::OnOK()::stat64'
    #0 61.63 npm ERR!    44 | #define STAT64_STRUCT stat64
    #0 61.63 npm ERR!       |                       ^~~~~~
    #0 61.63 npm ERR! ../src/pipeline.cc:1229:16: note: in expansion of macro 'STAT64_STRUCT'
    #0 61.63 npm ERR!  1229 |         struct STAT64_STRUCT st;
    #0 61.63 npm ERR!       |                ^~~~~~~~~~~~~
    #0 61.63 npm ERR! make: *** [sharp-linuxmusl-x64.target.mk:167: Release/obj.target/sharp-linuxmusl-x64/src/pipeline.o] Error 1
    

    Is there any version I can downgrade for now? I can't get the specific tag, but it seems to be this digest which was working for me: 4bdb3f3105718f0742bc8d64bb4e36e8f955ebbee295325e40ae80bc8ef78833

    I downgraded to node:18-alpine3.18 and everything is work for now, I'll continue to follow this issue to upgrade when I can

  6. yosifkit commented on Dec 13, 2023

    @yosifkit
    Contributor

    Ah, for some, this looks like a sharp module incompatibility with the newer libvips of the Alpine packages. In Alpine 3.18, libvips is 8.13.3, but it is 8.15.0 in Alpine 3.19 (https://pkgs.alpinelinux.org/packages?name=vips-dev&branch=v3.19).

    https://github.com/lovell/sharp/blob/v0.30.7/package.json#L157
    https://github.com/lovell/sharp/blob/v0.31.3/package.json#L158
    https://github.com/lovell/sharp/blob/v0.32.6/package.json#L162
    https://github.com/lovell/sharp/blob/v0.33.0/package.json#L190

    I think just updating your sharp dependency should be enough in some cases:

    $ docker run --rm node:18-alpine3.19 npm install -g sharp@0.30
    npm ERR! code 1
    npm ERR! path /usr/local/lib/node_modules/sharp
    npm ERR! command failed
    npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
    npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
    npm ERR! sharp: Installation error: Invalid Version: 1.2.4_git20230717
    
    npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-12-13T19_14_03_677Z-debug-0.log
    
    $ docker run --rm node:18-alpine3.19 npm install -g sharp@0.31
    npm ERR! code 1
    npm ERR! path /usr/local/lib/node_modules/sharp
    npm ERR! command failed
    npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
    npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
    npm ERR! sharp: Installation error: Invalid Version: 1.2.4_git20230717
    
    npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-12-13T19_14_11_327Z-debug-0.log
    
    $ docker run --rm node:18-alpine3.19 npm install -g sharp@0.32
    
    added 51 packages in 3s
    
    $ docker run --rm node:18-alpine3.19 npm install -g sharp@0.33
    
    added 15 packages in 2s
  7. ivanolarocca commented on Dec 14, 2023

    @ivanolarocca

    I confirm the problem using node:18-alpine3.19

    Running npm i this is the problem shown:

    npm ERR! code 1
    npm ERR! path /usr/src/app/node_modules/sharp
    npm ERR! command failed
    npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
    npm ERR! sharp: Installation error: Invalid Version: 1.2.4_git20230717

    Downgrade to node:18-alpine3.18 it works.

  8. IbrohimIsroilov commented on Dec 19, 2023

    @IbrohimIsroilov

    This is happening when node and sharp versions mismatch in my case. So I recommend trying to install both node and sharp latest versions. Either try downgrading both node and sharp versions as for your needs. In my case, node 16 and sharp 0.30.3 work fine. But sharp 0.30.3 doesn't work with node 20.

  9. HubertK778 commented on Dec 23, 2023

    @HubertK778

    Changing image from node:18-alpine to node:18-alpine3.18 in my Dockerfile worked for me.

  10. youxdd commented on Dec 25, 2023

    @youxdd

    Why do I still get an error after changing it to node:18-alpine3.18?

  11. downey88 commented on Dec 26, 2023

    @downey88

    I am using image node:20-alpine3.18 from node:18-alpine works for me..

  12. iRakic commented on Dec 26, 2023

    @iRakic

    It works for me also with node:18-alpine3.18. Hopefully, this will be fixed in the next releases.

  13. nschonni commented on Dec 26, 2023

    @nschonni
    Member

    The Alpine image never supported node-gyp building without additional packages being added. Instructions can be found here https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine
    Likely the Sharp or other packages were shipping pre-built binaries that aren't currently compatible with the newest Alpine image, no change in this repo will fix that.

  14. added a commit that references this issue on Dec 28, 2023
  15. evoactivity commented on Jan 11, 2024

    @evoactivity

    @nschonni I tried following those instructions using node:20-alpine, I had the same build error until I switched to node:20-alpine3.18 without those extra apt packages being installed.

  16. andersonaguia commented on Feb 2, 2024

    @andersonaguia

    For me it worked by changing the alpine version to 3.18.

    Dockerfile:
    FROM node:18-alpine3.18 AS build

  17. ticmaisdev commented on Feb 27, 2024

    @ticmaisdev

    working on node:21-alpine3.18

  18. steven1227 commented on Jun 8, 2024

    @steven1227

    still get the error when I use node:20-alpine3.18 or node:18-alpine3.18

  19. lolu20255 commented on Sep 5, 2024

    @lolu20255

    To resolve this, you need to ensure that Python is installed and available in the Docker image. Add the following to your Dockerfile

    FROM node:18-alpine
    
    # Install dependencies including Python
    RUN apk add --no-cache python3 py3-pip make g++ \
        && ln -sf python3 /usr/bin/python \
        && ln -sf pip3 /usr/bin/pip
    

    This worked for me.

  20. added a commit that references this issue on Mar 7, 2025
  21. added a commit that references this issue on Mar 7, 2025
  22. added a commit that references this issue on Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions