Open ryanylee opened 12 months ago
You seem to have missed this error when you run your build:
Error: 405 /about (linked from /)
To suppress or handle this error, implement `handleHttpError` in https://kit.svelte.dev/docs/configuration#prerender
Your Header
component contains <a href="/about">About</a>
, this is requiring /about
to need to be handled via a GET request or error handler in order to function. This is a sanity check.
Removing the link allows the build to succeed.
But what if I want to include the link?
The prerenderer crawls the root page /
but incorrectly prefers the endpoint over the page, even when it doesn't have a GET method, which causes the error.
Possibly related https://github.com/sveltejs/kit/issues/10515
This seems to be the root cause.
The prerenderer crawls the root page
/
but incorrectly prefers the endpoint over the page, even when it doesn't have a GET method, which causes the error.
This is enough to trigger the error.
<!-- src/routes/+page.svelte -->
// src/routes/+page.svelte
export const prerender = true;
// src/routes/+server.ts
export const POST = () => new Response(null);
In a new skeleton project, running pnpm build
will log the following message:
Error: 405 / - To suppress or handle this error, implement
handleHttpError
Describe the bug
In a route, I have a
+page.svelte
and+server.ts
file, and in the+server.ts
file I only have aPOST
method andexport const prerender = false
. When I build, it fails, but when I add an emptyGET
method, build runs perfectly fine.Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-p5tugw?description=The%20default%20SvelteKit%20template,%20generated%20with%20create-svelte&file=src%2Froutes%2Fabout%2F%2Bserver.js&title=SvelteKit%20Default%20Template
Logs
System Info
Severity
annoyance
Additional Information
No response