0

Similar to this issue SvelteKit with Nginx returns response error 500 but I am using Sveltekit's post Vite 3 update, Contentfuls JS API and the Sveltekit Netlify Adapter and do not wish to prerender data.

My folder structure looks like:

src/
│
├── index.svelte
├── data/
│   └── index.json.ts
│...
├── blog
│   └── [slug].svelte
│   └── [slug].json.ts

The json files has a simple promise call for the data, returning a status of 200 and the raw data or a 404 status.

I'm making use of Sveltekit's module load function like so:

    export const load = async ({ fetch, params }) => {
        const url = `data/${params.slug}.json`;
        const req = await fetch(url, {
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
        })
        .then((res) => {
            console.log("BlurbData Res: ", res);
            if (res.status !==200) {
                throw new Error (`Could not load data. Status ${res.status}`)
            }
            return res.json()
        })

        const blurbData = await req;

        return {
            props: {
                data: blurbData
            }
        }
    }

Which works fine locally. Even running vite build and vite preview commands fetch data and load the content fine, but only when trying to access my app on Netlify do I get a 500 response like so:

500
Could not load data. Status 500
Error: Could not load data. Status 500

I have even updated my netlify.toml root file to include the functions path which moves Svelte endpoints to Netlify functions. So what could be the problem? Why do I get 500s on the production env on Netlify?

Feel free to take a look at how I'm handling the data in this repo.

LionOnTheWeb
  • 326
  • 2
  • 16
  • Did you figure this out? I have a similar problem (but using `@sveltejs/adapter-node`) – jost21 Oct 10 '22 at 21:16
  • @jost21 not really; my guess was that the Netlify-adapter didn't sit well with Svelte/kit's routing updates with Vite. I switched to Vercel instead of Netlify, and everything immediately worked. These issues will likely happen because Svelte/kit is still in beta. – LionOnTheWeb Oct 13 '22 at 01:10

0 Answers0