next.js standalone 빌드 sharp 0.33 이슈

zori (html programmer)·2024년 5월 10일
0

이 글을 찾으셨다면 sharp가 동작하지 않아 마음고생이 심하셨을 것으로 예상됩니다 심심한 위로의 말씀을 드립니다.

글이 도움이 되시는 분들의 환경입니다. nextjs 12, 13, 14(일부 버전), sharp 0.33+, standalone 빌드 사용

0.33 부터 sharp의 바이너리 파일들은 node_modules/@img 에 생성되는데 패키지 install 시에는 있던 node_modules/@img 파일들이 빌드 후에는 node_modules/@img 가 없으실 겁니다. 즉 node_modules/@img를 다시 가지고 오면 해결됩니다.

https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
위 도커 파일 기준

RUN mkdir -p .next ./node_modules/@img
RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@img ./node_modules/@img

만약 install부터 @img가 없으시다면 환경에 맞는 패키지를 수동 install 해주세요.
ex)
RUN yarn add @img/sharp-linux-x64 --ignore-engines
RUN yarn add @img/sharp-linuxmusl-x64 --ignore-engines

profile
HTML개발자 입니다.

0개의 댓글