fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

In prod build, all pages (except /) return 404 when server rendered #98

Closed nickrobillard closed 7 years ago

nickrobillard commented 7 years ago

When I test a prod build (next build and next start), server generated sub-pages return 404. This is reproducible with the next-routes example in the next repo - https://github.com/zeit/next.js/tree/master/examples/with-next-routes.

Steps to reproduce:

  1. Follow installation instructions (https://github.com/zeit/next.js/tree/master/examples/with-next-routes)
  2. Run commands next build followed by next start
  3. Navigate to the first link Blog: Hello world
  4. Refresh page and observe 404

I'm assuming this was working at some point. Maybe this was introduced in Next.js v3?

screen shot 2017-09-12 at 8 49 30 pm
nickrobillard commented 7 years ago

Ok this is my bad. I should have been using npm run start or yarn start to start the prod server. Issue resolved.

bntzio commented 7 years ago

@nickrobillard How did you solve it? I'm facing the same error on production only, 404 for sub-pages as well if I enter directly, but not if using <Link>.

nickrobillard commented 7 years ago

In Step 2, replace npm start with npm run start or yarn start. npm start starts the server with default next config, which is wrong because this example uses a custom server. Credit goes to @grokling on slack for catching this.

bntzio commented 7 years ago

Oh got it!! Do we need to run our own server (node server.js) instead of the next.js one (next start) right?

It's working now 😄 thanks!

nickrobillard commented 7 years ago

Yes, you can see this in the example's package.json. The build script runs NODE_ENV=production node server.js.

andrewmartin commented 4 years ago

Oh man, thank you so much. Was wrangling with this one for a minute and driving myself nuts...Realized I had a wonky ecosystem.config.js using npm run start instead of yarn start