Next.js: Export 404.html when running `next export` without `exportPathMap`

Created on 27 Aug 2018  路  11Comments  路  Source: vercel/next.js

Feature request

Is your feature request related to a problem? Please describe.

next export's defaultPathMap contains /_error which is not supported as error page by most browsers. What however is supported is 404.html.

Describe the solution you'd like

Updating https://github.com/zeit/next.js/blob/canary/server/export.js#L34

To have the following statement:

if(page === '/_error') {
  defaultPathMap['404'] = { page }
  continue
}

This will make next export export 404.html with the contents of /_error

Describe alternatives you've considered

The alternative is doing this manually in exportPathMap

module.exports = {
  exportPathMap(defaultPathMap) {
    defaultPathMap['404'] = defaultPathMap['/_error']
    return defaultPathMap
  }
}

Additional context

Feature request originated on this spectrum.chat thread: https://spectrum.chat/thread/f765b794-9aa9-4edc-b549-6de2268847e5

Most helpful comment

Correct

All 11 comments

cc @kylemh as you surfaced this on zeit.chat

Claiming (if that's a thing)

You can run the specific test suite using yarn testonly --testPathPattern "static" -t "Render via SSR" or when you added the test replace Render via SSR with <your test name>

I'm expecting this is because the files are exported in a subdir 404/index.html. Let's fix that.

@timneutkens I'll dive in next week to see If I can get to it on my own 馃憤

I imagine it'll be some sort of conditional logic around here: https://github.com/zeit/next.js/blob/canary/export/index.js#L124

Correct

I'm having this problem too, we change the _error.js code to a better-looking page. So, we just send our NextJS app to production using Zeit Now, and everything works BUT the 404 error page, I don't know how, but it's loading the default error page, but that page doesn't exist anymore, it should load the actual _error.js and it's not happening, any idea why is happening?

Lot of context on this issue and a resolution for you here: https://github.com/zeit/now-builders/issues/234

Cross posting for visibility, thanks @kylemh!

"routes": [
  // ...otherRoutes,
  { "handle": "filesystem" },
  { "src": "/.*", "dest": "/_error" }
],

_Originally posted by @kylemh in https://github.com/zeit/now-builders/issues/234#issuecomment-497031992_

Was this page helpful?
0 / 5 - 0 ratings