(self-host) next start makes 404 page
Answered
Giant panda posted this in #help-forum
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 ?
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.
FIX: Just delete it whenever it appears.
46 Replies
Giant pandaOP
Did the same with a standalone build.
Looks like there's an issue with the src folder, or the app-directory.
Looks like there's an issue with the src folder, or the app-directory.
show me your structure
take a screenshot
Giant pandaOP
what is prevent.middleware.ts
Giant pandaOP
A temporary file
how does your app/ look like
and next config
Giant pandaOP
Looks like it creates an empty app directory at the root path
there is nothing inside app/
?
Giant pandaOP
Nothing, my app directory is located in src/app
and what does your src/app look like
Giant pandaOP
ok looks good
next config?
Giant pandaOP
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ['picsum.photos'],
},
output: 'standalone',
};
export default nextConfig;
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...
Giant pandaOP
What do you mean by that ?
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
Giant pandaOP
Dev is working
cool
.
Giant pandaOP
Yes but it's not working as well
ok
Giant pandaOP
It copy and pastes the app directory but with no any content after the build
cf. Dockerfile :
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)
try adding this line
ENV HOSTNAME="0.0.0.0"
above CMD ["bun", "run", "server.js"]
Giant pandaOP
That’s bad routing issue, last time it was working without it imo
Giant pandaOP
Hey bumping sorry!
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)
(i just want to know if bun is the issue)
Giant pandaOP
I’ve tried with bun / node and yarn
cool cool
Giant pandaOP
Looks like only a routing issue, it’s weird
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
Giant pandaOP
Yeah of course just in case
sadly i cant help that much as i dont know docker very well 😔
what is creating the app folder at the root?
src/app
is ignored if there is /app
Giant pandaOP
I mean, it’s creating sometimes an empty app directory outside the src folder. With no any content inside
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.
FIX: Just delete it whenever it appears.
Answer