question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a straightforward way to export error pages with `adapter-static`

See original GitHub issue

Is your feature request related to a problem? Please describe. There doesn’t seem to be a proper way to export a 404 for static sites. In Sapper, adding /404 as a second entry point would export an additional /404/index.html; in SvelteKit, there is currently no similar option.

Related to #1172, but with the specific goal of handling non-SPA exports.

Describe the solution you’d like Assuming this has no value outside of static export, it probably should be a separate option for adapter-static. Error routes should not be required to explicitly exist and should be exempt from the default ‘fail on error’ policy.

(A nice touch would be the ability to trigger specific errors from here, e.g. by passing error codes for prerendering. This way, websites that need more than a simple 404 (e.g. sites operating within larger systems may also want 502 and 504) could be catered for. I wonder, however, if this is common enough to mind.)

Describe alternatives you’ve considered In theory, offering a way to force prerendering no matter the status code would allow simply adding separate entries in the config, effectively replicating Sapper’s behaviour. This would be undesirable, as I believe SvelteKit’s ‘all errors are build errors’ behaviour is excellent and should remain otherwise intact.

A workaround currently requires error routes to exist as normal pages. This works, but leads to some duplication between $error.svelte and 404.svelte, is not very portable (a 404.svelte that in fact returns 200 makes no sense with, say, adapter-node), and generally ticks all boxes to qualify as a hack.

How important is this feature to you? A 404 page is important in static export, and relying on hacks in performing such a common task shouldn’t be necessary.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
lukeedcommented, Jul 18, 2021

What I’m doing now is src/routes/404.svelte – which builds to /build/404/index.html (currently using static adapter).

So then I add a postbuild npm script to move that file to the correct location:

{
  // ...
  "scripts": {
    "build": "svelte-kit build",
    "postbuild": "mv build/404/index.html build/404.html"
  }
}
7reactions
intrikatecommented, Apr 25, 2021

Oh, right, thanks, I missed this one. An option would be nice indeed.

However, the resulting fallback doesn’t render a 404 using $error.svelte, it simply renders a blank page with spa: true, which ultimately solves a different problem.

What am I still missing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploy a Svelte site · Cloudflare Pages docs
Documentation for Cloudflare Pages, the best way to deploy your static and JAMstack sites.
Read more >
sveltekit adapter-static non-SPA error pages : r/sveltejs - Reddit
I am using adapter-static with no Fallback (i.e non-SPA mode). but,there is no error page(server itself resolves and returns error 404) in ...
Read more >
Minimal Sveltekit + pg integration fails with "status" error
My bad - the hooks function wasn't returning the response. Hooks.server.js should read: import { connectToDB } from '$lib/db'; export const ...
Read more >
Migrating from Sapper • Docs • SvelteKit
You will need to add an adapter. sapper build is roughly equivalent to adapter-node while sapper export is roughly equivalent to adapter-static, ...
Read more >
Cisco UCS Manager GUI Configuration Guide, Release 2.2
Starting the KVM Console from the Cisco UCS KVM Direct Web Page 725. CHAPTER 41 ... Configuring the All Configuration Export Policy 747....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found