Error loading shared library libcairo.so.2: No such file or directory

I created a build layer in my Dockerfile but didn’t apk add the required packages to the app layer. And so libcairo couldn’t find the files it depends on.

Broken Version

FROM node:alpine3.16 as build
WORKDIR /app
RUN apk add --update --no-cache     build-base     cairo-dev     jpeg-dev     pango-dev     giflib-dev     libtool
COPY . .
RUN npm ci


FROM node:alpine3.16
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["npm", "start"]

Working Version

FROM node:alpine3.16 as build
WORKDIR /app
RUN apk add --update --no-cache     build-base     cairo-dev     jpeg-dev     pango-dev     giflib-dev     libtool
COPY . .
RUN npm ci
ENTRYPOINT ["npm", "start"]
#whyprogrammingissohard