NextJS runs differently in docker than npm run start
Answered
North Pacific hake posted this in #help-forum
North Pacific hakeOP
Hi there, I am having a very weird issue that I have never had before.
Previously I deployed all of my projects with docker and it worked fine. With my current deployment there is a severe issue.
The issue presents itself as rendering client side components on routes where it should not be rendering. Some of these components handle auth which are in a
I have tried the following:
1. Returning on the auth client component at the start of the file so that no logic gets executed.
2. Removing middleware.
Here is my dockerfile
Not sure what else there is to try, really weird...
Previously I deployed all of my projects with docker and it worked fine. With my current deployment there is a severe issue.
The issue presents itself as rendering client side components on routes where it should not be rendering. Some of these components handle auth which are in a
app/app
layout, however it seems to trigger on /
route. When I do npm run build
and then npm run start
it works fine, however, when I do the same exact thing but in docker the issues start. No errors, no terminal output. Just extremely weird functionality.I have tried the following:
1. Returning on the auth client component at the start of the file so that no logic gets executed.
2. Removing middleware.
Here is my dockerfile
FROM node:21-alpine
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3000
RUN npm run build
CMD ["npm", "run", "start"]
Not sure what else there is to try, really weird...
Answered by North Pacific hake
Hey, thanks for the reply,
The issue was that in /app/app I had layout.js (which worked fine in NextJS 14...), changing it to .jsx fixed it.
The issue was that in /app/app I had layout.js (which worked fine in NextJS 14...), changing it to .jsx fixed it.
3 Replies
Spectacled bear
Hi @North Pacific hake Based on your description, you're experiencing a problem where client-side components are rendering incorrectly in your Docker deployment, specifically with auth related components appearing on routes where they shouldn't. This works fine in local development but fails in Docker.
FROM node:21-alpine AS builder
WORKDIR /app
COPY package*.json ./
COPY .npmrc ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:21-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/node_modules ./node_modules
ENV NODE_ENV production
EXPOSE 3000
CMD ["npm", "run", "start"]
@Spectacled bear Hi <@910503868876587010> Based on your description, you're experiencing a problem where client-side components are rendering incorrectly in your Docker deployment, specifically with auth related components appearing on routes where they shouldn't. This works fine in local development but fails in Docker.
North Pacific hakeOP
Hey, thanks for the reply,
The issue was that in /app/app I had layout.js (which worked fine in NextJS 14...), changing it to .jsx fixed it.
The issue was that in /app/app I had layout.js (which worked fine in NextJS 14...), changing it to .jsx fixed it.
Answer