Next.js Discord

Discord Forum

(self-host) next start makes 404 page

Answered
Giant panda posted this in #help-forum
Open in Discord
Avatar
Giant pandaOP
Hello I'm encountering an issue

When I deploy via (npm run build && npm run start) so next build and next start it displays a nextjs 404 page.

I'm using src directory and app-router.

Any clues please ?
Answered by Giant panda
Okay found the error, sometime, I don't know why, running the next build and start, create an empty app directory outside the src, and the next start considers it as a the actual app folder so it renders no any routes.

FIX: Just delete it whenever it appears.
View full answer

46 Replies

Avatar
Giant pandaOP
Did the same with a standalone build.

Looks like there's an issue with the src folder, or the app-directory.
Avatar
show me your structure
take a screenshot
Avatar
Giant pandaOP
Image
Avatar
what is prevent.middleware.ts
Avatar
Giant pandaOP
A temporary file
Avatar
how does your app/ look like
and next config
Avatar
Giant pandaOP
Image
Looks like it creates an empty app directory at the root path
Avatar
there is nothing inside app/
?
Avatar
Giant pandaOP
Nothing, my app directory is located in src/app
Avatar
and what does your src/app look like
Avatar
Giant pandaOP
Image
Avatar
ok looks good
next config?
Avatar
Giant pandaOP
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    domains: ['picsum.photos'],
  },
  output: 'standalone',
};

export default nextConfig;
Avatar
ok i stop here cause there is literally so many reasons its not working as expected for you
if npm run dev works
then clear your cache
and make sure the routes are correctly defined...
Avatar
Giant pandaOP
What do you mean by that ?
Avatar
well if this is your project you should know if your conventions are correctly
if accessing / shows a 404 you def made something wrong in your routing setup
Avatar
Giant pandaOP
Dev is working
Avatar
cool
.
Avatar
Giant pandaOP
Yes but it's not working as well
Avatar
ok
Avatar
Giant pandaOP
It copy and pastes the app directory but with no any content after the build

cf. Dockerfile :
FROM oven/bun:alpine AS base

# Stage 1: Install dependencies
FROM base AS deps
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

# Stage 2: Build the application
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN bun run build

# Stage 3: Production server
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 3000
CMD ["bun", "run", "server.js"]


(credit:From the CEO, video about selfhosting)
Avatar
try adding this line ENV HOSTNAME="0.0.0.0" above CMD ["bun", "run", "server.js"]
Avatar
Giant pandaOP
That’s bad routing issue, last time it was working without it imo
Avatar
Giant pandaOP
Hey bumping sorry!
Avatar
just to check, if you use node to build and start (you can still keep bun install), does it work as intended

(i just want to know if bun is the issue)
Avatar
Giant pandaOP
I’ve tried with bun / node and yarn
Avatar
cool cool
Avatar
Giant pandaOP
Looks like only a routing issue, it’s weird
Avatar
but i mean like using node to start and build, nothing to do with package manager
bun should work well anyway, so i doubt it was the issue
Avatar
Giant pandaOP
Yeah of course just in case
Avatar
sadly i cant help that much as i dont know docker very well 😔
Avatar
what is creating the app folder at the root? src/app is ignored if there is /app
Avatar
Giant pandaOP
I mean, it’s creating sometimes an empty app directory outside the src folder. With no any content inside
Avatar
Giant pandaOP
Okay found the error, sometime, I don't know why, running the next build and start, create an empty app directory outside the src, and the next start considers it as a the actual app folder so it renders no any routes.

FIX: Just delete it whenever it appears.
Answer