NextJS (13.5.4) with custom ExpressJS server, does not render any pages.
Unanswered
French Lop posted this in #help-forum
French LopOP
Hi everyone,
I'm struggling to get NextJS to render any pages when using it with a custom ExpressJS server.
The incoming route gets matched by Express and the root NextJS layout gets called (page title gets set), but then it just responds with a 404 and a blank page.
I'm using the new
I've made a MPV repo that demonstrates the issue..
https://github.com/latchy/express-next-js
Any advice would be greatly appreciated. Thanks in advance!
I'm struggling to get NextJS to render any pages when using it with a custom ExpressJS server.
The incoming route gets matched by Express and the root NextJS layout gets called (page title gets set), but then it just responds with a 404 and a blank page.
I'm using the new
/app structure, and everything is in TypeScript.I've made a MPV repo that demonstrates the issue..
https://github.com/latchy/express-next-js
Any advice would be greatly appreciated. Thanks in advance!
43 Replies
Spectacled Eider
for the empty screen from debugging i found that it is not serving the .next folder correctly
now i am looking for why is he returning 404 even when the files are being served
Spectacled Eider
for some reason the handler
const handle = nextjs.getRequestHandler();
its not working properly i don't really know why
( i just looked now and is not it's fault, the normal next js server is returning this error of 404 but the blank screen its caused by it)
const handle = nextjs.getRequestHandler();
its not working properly i don't really know why
( i just looked now and is not it's fault, the normal next js server is returning this error of 404 but the blank screen its caused by it)
French LopOP
Huuuh, curious - thanks for checking this out btw
French LopOP
I've been fighting this issue since Monday morning.
I've actually got a more complex app, which does localisation and is in Docker, its a part of a microservices monorepo that uses Lerna and all of a sudden I restarted the service and it gave an error regarding a missing module from an i18n lib, but in the process of fixing that, its lead me to this issue.
I've actually got a more complex app, which does localisation and is in Docker, its a part of a microservices monorepo that uses Lerna and all of a sudden I restarted the service and it gave an error regarding a missing module from an i18n lib, but in the process of fixing that, its lead me to this issue.
So honestly, at this point, I'd pay whoever can get help get it fixed!
@Spectacled Eider if you do work anything out plz plz do @ me 🙂
Spectacled Eider
@French Lop i think i found a workaround for this error
Spectacled Eider
the error is in the next.js configs
the
caused that error. by default its value is true
useFileSystemPublicRoutes: false,caused that error. by default its value is true
Spectacled Eider
the only problem that i found when doing this is that when going in to a non-existent page it defaults to /
but when its active it doesn't serve the files in the right way
French LopOP
OK, thats interesting!
Spectacled Eider
looks like it disables filename routes from SSR
when active
French LopOP
Right - so I've checked my git history and its been set to false for the last year
my understanding was that it was used for Next to do route matching from the pages folder if a route had not been matched by the custom server
My express server should be matching that endpoint this I don't need NextJS file system routing
so yeah, this disabled only SSR routes as it says - which express should handle
the bothering thing is, as I mentioned, I've had repo just like this working for months, if not over a year
so I'm generally just rather confused aha 😅
French LopOP
So it looks like this config works on v13.0.0 of next, when using the /app directory.
Thought it does still fail to load some /_next/static/chunks ..
const next_config = {
experimental: {
appDir: true,
},
useFileSystemPublicRoutes: false,
};Thought it does still fail to load some /_next/static/chunks ..
I've tried getting the /pages directory to work but nothing.
@French Lop So it looks like this config works on v13.0.0 of next, when using the /app directory.
const next_config = {
experimental: {
appDir: true,
},
useFileSystemPublicRoutes: false,
};
Thought it does still fail to load some /_next/static/chunks ..
French LopOP
Can confirm this does not then work when upgrading top next@13.5.4
Spectacled Eider
what i found weird is that when i manually serve the .next files it does not render the page.tsx
French LopOP
I've got to head out but I think a bug has been introduced between v13.0.0 and v13.5.4
Also still don't know why it doesn't work even on v13.0.0 with the /pages dir ..
Also still don't know why it doesn't work even on v13.0.0 with the /pages dir ..
is it even intended to run nextjs with custom express server and not
next start?French LopOP
Yes, it's documented somewhere and even given in an official example somewhere
Spectacled Eider
i was looking at this example here to get reference: https://stackblitz.com/edit/github-6mzuef-r5bkvo
nice but i see that that is pages dir, do we have app dir docs? (or should it be similar)
French LopOP
It's so you can use NextJS SSR and Dev tooling without depending on serverless deployments etc
but
next start isn't serverless?French LopOP
If you do a fresh pull I've created examples for /pages and /app in versions 13.0.0 and 13.5.4
Spectacled Eider
This one uses a custom server and app router but doesn't use typescript
@riský ~~btw unrelated to this, but your robots.txt and favicon.ico can go directly in app dir (favicon will auto be linked in head)~~ (edit, i see you are having them actually there for your express server to use)
French LopOP
I'm using it to show how express can handle those assets
yeah i just realised that
French LopOP
I'm out at the moment but later I want to step forward through the versions from 13.0.0 to see where the thing starts breaking
With the /app directory.. while also working out how to get the /pages directory working again