0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ECSタスク作成後に Error: Cannot find module '/app/.next/prerender-manifest.json' が出る場合の対応

Posted at

AWSコンテナ設計・構築 本格入門 P288「フロントエンドアプリケーションからの一気通貫確認」で詰まったので備忘録。

元のDockerfiledのままdocker biliddocker image pushしたイメージを使用してECSタスクを作成すると起動に失敗する。ECSタスクないのログを確認すると

Error: Cannot find module '/app/.next/prerender-manifest.json'

というエラーが発生していた。

Node.js 14だとprerender-manifest.jsonが作成されないようなので、16系に変更してbuildしたところECSタスクを起動できた。

Dockerfile

不要なものも混じってると思うが、一応以下でECSタスクの起動とフロントからの疎通確認ができた。

FROM node:16-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app
RUN apk add --update --no-cache --virtual build-deps \
    python3 \
    py3-pip \
    g++ \
    git \
    libtool \
    automake \
    autoconf \
    make \
    openssl1.1-compat

# Install Python distutils
RUN python3 -m pip install setuptools

# Add libvips
RUN apk add --upgrade --no-cache vips-dev build-base --repository https://alpine.global.ssl.fastly.net/alpine/v3.10/community/
COPY . .

# Set environment variables for Next.js build
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV NEXT_STATIC_BUILD=true
ENV PYTHON=/usr/bin/python3

# install production dependencies
RUN yarn install --frozen-lockfile --production --network-timeout 600000

# Note also that prisma generate is automatically invoked when you're installing the @prisma/client npm package
RUN npx prisma generate

# Save production depenencies installed so we can later copy them in the production image
RUN cp -R node_modules /tmp/node_modules

# install all dependencies including devDependencies
RUN yarn install --frozen-lockfile --network-timeout 600000

# Build with explicit Next.js configuration
RUN yarn build && \
    yarn next export || true

# Verify .next directory contents
RUN ls -la .next/

###########
FROM node:16-alpine
WORKDIR /app

RUN apk add --no-cache curl tzdata openssl1.1-compat && \
    cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
    apk del tzdata

COPY --from=builder /tmp/node_modules ./node_modules
COPY --from=builder /app/.blitz ./.blitz
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package.json ./
COPY --from=builder /app/db ./

# Verify copied .next directory
RUN ls -la .next/

ENV PORT=80
EXPOSE 80

CMD [ "npm","run","start:prd" ]
# HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?