Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+server.ts must have a GET method or build fails #10735

Open
ryanylee opened this issue Sep 14, 2023 · 5 comments · May be fixed by #12998
Open

+server.ts must have a GET method or build fails #10735

ryanylee opened this issue Sep 14, 2023 · 5 comments · May be fixed by #12998
Labels
bug Something isn't working

Comments

@ryanylee
Copy link

ryanylee commented Sep 14, 2023

Describe the bug

In a route, I have a +page.svelte and +server.ts file, and in the +server.ts file I only have a POST method and export const prerender = false. When I build, it fails, but when I add an empty GET 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

Error: 405 /about (linked from /)
To suppress or handle this error, implement `handleHttpError` in https://kit.svelte.dev/docs/configuration#prerender

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.20.4 => 1.25.0 
    svelte: ^4.0.5 => 4.2.0 
    vite: ^4.4.2 => 4.4.9

Severity

annoyance

Additional Information

No response

@SudoerWithAnOpinion
Copy link

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.

@ryanylee
Copy link
Author

But what if I want to include the link?

@eltigerchino eltigerchino added the bug Something isn't working label Sep 24, 2023
@eltigerchino
Copy link
Member

eltigerchino commented Sep 24, 2023

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.

@eltigerchino
Copy link
Member

Possibly related #10515

@hyunbinseo
Copy link
Contributor

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

@eltigerchino eltigerchino linked a pull request Nov 14, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants