Next.js: Custom server with express not working in production mode

Created on 2 Mar 2017  路  10Comments  路  Source: vercel/next.js

I was running my project with express, then I saw an issue in production mode so I replicated the custom-server-express example and the same issue was there:

issue

(using nextjs beta 36) It is only happening with npm run start. everything seems to be fine in dev.

Most helpful comment

The reason is next start only runs the next.js part..

You should next build then start with NODE_ENV=production node server.js

You can also trigger the build programmatically from dist/server/build

All 10 comments

You could create a repo in github with the code or create a gist.

@Goluis is this persist even you reload the page?

@arunoda Yes, but only when I'm using NODE_ENV in' production, when I switch to dev everything works fine, except that the initial page load is always 1.5s or more

Okay. This happens when you run npm run start without npm run build
If you just run npm start just after npm run dev, you running dev build with production server.
Which doesn't work pretty well.

Re-open if this's not the case.

@arunoda, Should we show a warning in this case?

We Already do in 'next start'

When running in production mode with 'next start', custom routes in the server side do not work. It seems it ignores server.js.

This is the case even in https://github.com/arunoda/learnnextjs-demo.git. Where urls like http://localhost:3000/p/hello-nextjs won't work from the server side.

If we run the run in production mode with 'NODE_ENV=production node server.js', custom routes work fine.

The reason is next start only runs the next.js part..

You should next build then start with NODE_ENV=production node server.js

You can also trigger the build programmatically from dist/server/build

@reel FYI https://github.com/zeit/next.js/issues/1326#issuecomment-283563364 has been fixed 馃憣 If there is no build it'll show a warning when using custom server to 馃槃

Was this page helpful?
0 / 5 - 0 ratings