Closed jenssegers closed 4 days ago
Setting SHARP_FORCE_GLOBAL_LIBVIPS=1
seems to have fixed the issue. The installation instructions suggested that this was not required if a global libvips was detected.
This did uncover that the alpine 3.20 libvips version was not sufficient so I had to change to:
RUN apk add --no-cache --update \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
vips \
vips-dev \
vips-heif \
libheif \
libpng \
libjpeg-turbo \
libde265 \
libwebp \
g++ \
make \
gcc \
build-base
The part of the installation log just before the section you've provided here should have included entries with information about what sharp discovered and the decisions it made when attempting to build from source.
As you've seen, the version of the vips-dev
package provided by Alpine 3.19 is not recent enough for the latest sharp v0.33.5. You don't need to set (and I recommend against setting) SHARP_FORCE_GLOBAL_LIBVIPS
unless you know that version mismatches should be ignored.
If you don't need to use a globally-installed libvips then I'd suggest not installing it and letting sharp using its prebuilt binaries, which removes a whole class of possible installation error.
@lovell As you can see from the dependencies, I needed support for heif images.
If anyone hits this post from a search, this is my current (simplified) multi-layer Dockerfile to build Sharp with heif support on Alpine:
FROM node:20-alpine AS sharp
# Force global libvips
ENV SHARP_FORCE_GLOBAL_LIBVIPS=1
# Set working directory
WORKDIR /sharp
# Install dependencies
RUN apk add --no-cache --update \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \
--repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
vips \
vips-dev \
vips-heif \
libheif \
libpng \
libjpeg-turbo \
libde265 \
libwebp \
g++ \
make \
gcc \
build-base
# Install Sharp
RUN npm install --no-package-lock --save-dev node-addon-api node-gyp && \
npm install --no-package-lock --build-from-source --include=optional --verbose --foreground-scripts --platform=linux --libc=musl --arch=arm64 sharp && \
npm prune --production && \
npm cache clean --force
# Remove build dependencies
RUN apk del \
g++ \
make \
gcc \
build-base
# ------------------------------------------------------------
FROM node:20-alpine
# Copy Sharp
COPY --from=sharp /sharp/node_modules ${LAMBDA_TASK_ROOT}/node_modules
COPY --from=sharp /usr/lib /usr/lib
Warning: please be very, very careful when mixing Alpine packages from edge
with stable
(non-edge) versions.
Possible install-time or require-time problem
You must confirm both of these before continuing.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of
sharp
that is not the latest, please open an issue against that package instead.Are you using a supported runtime?
^18.17.0 || ^20.3.0 || >=21.0.0
If you cannot confirm any of these, please upgrade to the latest version and try again before opening an issue.
Are you using a supported package manager and installing optional dependencies?
--include=optional
--no-optional=false
If you cannot confirm any of these, please upgrade to the latest version of your chosen package manager and ensure you are allowing the installation of optional or multi-platform dependencies before opening an issue.
What is the complete error message, including the full stack trace?
What is the complete output of running
npm install --verbose --foreground-scripts sharp
in an empty directory?See above.
What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?Dependencies installed within the container