1

When running an npm install locally everything is fine but as soon as I try it inside my docker container I get the following error:

/api/node_modules/sharp/lib/constructor.js:1
    Something went wrong installing the "sharp" module
    
    Error relocating /api/node_modules/sharp/build/Release/../../vendor/8.10.6/lib/libvips-cpp.so.42: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev: symbol not found

Any help greatly appreciated!

Docker image is incredibly simple:

FROM node:12.13.0-alpine AS alpine

WORKDIR /api

COPY package.json .

RUN npm install
Jamie
  • 1,004
  • 1
  • 14
  • 32
  • Do you have a [`.dockerignore` file](https://docs.docker.com/engine/reference/builder/#dockerignore-file) that includes the host's `node_modules` tree? The host and container environments can be very different (especially if the container is Alpine-based) and you need to make sure to start the package installation from scratch. – David Maze May 16 '21 at 20:40
  • 1
    @DavidMaze I don't - I did eventually get this working by a process of eliminiation, I had to add an explicit `RUN npm config set unsafe-perm true` to my Dockerfile and it was fine. – Jamie May 17 '21 at 14:13

2 Answers2

1

In my case after trying a lot of different options from scouring the github issues for Sharp, the addition of this line to my Dockerfile fixed it:

RUN npm config set unsafe-perm true
Jamie
  • 1,004
  • 1
  • 14
  • 32
1

In case you are using node:15 or later, --unsafe-perm was removed, this is a workaround:

...

RUN chown root.root .  # make sure root own the directory before installing Sharp
RUN npm install
Tai Vu
  • 101
  • 1
  • 3