Better error messages from selfhosted docker nextjs?
Unanswered
Arboreal ant posted this in #help-forum
Arboreal antOP
Hi All,
I'm self hosting nextjs in a docker container (for now). Everything is working mostly smoothly, but when things go wrong it's almost impossible to figure out why.
I get error messages like this:
That's usually because some server action couldn't be called, or was dodgy, or w.e. My gripe isn't with the error, it's with figuring out what caused the error.
Is there anyway to improve the error output experience when selfhosting? Ideally by including source maps or something so that specific files and lines of code are highlighted, rather than obscure positions in budled code.
I'll post the dockerfile in a moment.
I'm self hosting nextjs in a docker container (for now). Everything is working mostly smoothly, but when things go wrong it's almost impossible to figure out why.
I get error messages like this:
Error: Failed to find Server Action "null". This request might be from an older or newer deployment. Original error: Invariant: Missing 'next-action' header.
at rv (/app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:1666)
at /app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:7002
at AsyncLocalStorage.run (node:async_hooks:346:14)
at rg (/app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:15:6317)
at rz (/app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:24715)
at /app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:27397
at AsyncLocalStorage.run (node:async_hooks:346:14)
at Object.wrap (/app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:13:16207)
at /app/apps/frontend/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:27287
at AsyncLocalStorage.run (node:async_hooks:346:14)That's usually because some server action couldn't be called, or was dodgy, or w.e. My gripe isn't with the error, it's with figuring out what caused the error.
Is there anyway to improve the error output experience when selfhosting? Ideally by including source maps or something so that specific files and lines of code are highlighted, rather than obscure positions in budled code.
I'll post the dockerfile in a moment.
3 Replies
Arboreal antOP
FROM node:20-alpine AS base
# -----------------------------------------------------
FROM base AS pruner
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
COPY . .
RUN npx turbo prune frontend --docker
# -----------------------------------------------------
FROM base AS builder
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/package-lock.json ./package-lock.json
RUN npm install
COPY --from=pruner /app/out/full/ .
COPY --from=pruner /app/.prettierignore /app/.prettierignore
COPY --from=pruner /app/.prettierrc /app/.prettierrc
RUN npx turbo run build --filter=frontend...
# -----------------------------------------------------
FROM base AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs
COPY --from=builder /app/apps/frontend/next.config.js .
COPY --from=builder /app/apps/frontend/package.json .
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/apps/frontend/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/frontend/.next/static ./apps/frontend/.next/static
# COPY --from=builder --chown=nextjs:nodejs /app/apps/frontend/public ./apps/frontend/public # add public files if they are implemented later
CMD node apps/frontend/server.jsArboreal antOP
Is 'productionBrowserSourceMaps' the option I want?
Arboreal antOP
I added productionBrowserSourceMaps and the logs still aren't very helpful 😢 Is there anyway to figure out what's causing this error? It only happens to one of my users.