Skip to content

Unable to fetch server-side #1593

@thislooksfun

Description

@thislooksfun

Describe the bug
Running await fetch('/api/v1/ping') on the server crashes with Invalid URL

Logs
See the stacktrace.

To Reproduce

<script lang="ts" context="module">
  import type { Load } from "@sveltejs/kit";

  export const load: Load = async () => {
    await fetch("/api/v1/ping");
    return {};
  };
</script>

Expected behavior
I expect that it won't crash.

Stacktraces

Stack trace

Invalid URL
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:363:5)
at onParseError (node:internal/url:537:9)
at new URL (node:internal/url:613:5)
at new Request (file:///Users/tlf/Programming/Node/ecs/node_modules/@sveltejs/kit/dist/install-fetch.js:1239:16)
at file:///Users/tlf/Programming/Node/ecs/node_modules/@sveltejs/kit/dist/install-fetch.js:1448:19
at new Promise ()
at fetch (file:///Users/tlf/Programming/Node/ecs/node_modules/@sveltejs/kit/dist/install-fetch.js:1446:9)
at Module.get (/Users/tlf/Programming/Node/ecs/src/lib/util.ts:2:26)
at index.svelte:8:25
at Generator.next ()

Information about your SvelteKit Installation:

Diagnostics

System:
OS: macOS 11.3.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 1.36 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.2.0 - ~/.nvm/versions/node/v16.2.0/bin/node
npm: 7.13.0 - ~/.nvm/versions/node/v16.2.0/bin/npm
Browsers:
Firefox Developer Edition: 89.0
Safari: 14.1
npmPackages:
@sveltejs/kit: next => 1.0.0-next.110
svelte: ^3.34.0 => 3.38.2

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of SvelteKit entirely?

Very annoying, and goes directly against the documentation.

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions