Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sveltekit: Cannot stringify arbitrary non-POJOs on one table, but not others

Running into a bit of an odd issue. I'm using sveltekit and prisma with postgres. I'm loading data like so in my +page.server.ts file:

import type { PageServerLoad } from "./$types"
import { prisma } from "$lib/server/prisma"

export const load = (async () => {
    const response = {
        companies: await prisma.companies.findMany(),
        barges: await prisma.barges.findMany(),
        parish_tax: await prisma.parish_tax.findMany()
    }
    return { feed: response };
    }) satisfies PageServerLoad;

The companies and barges tables load fine. The parish_tax portion throws the following error:

Error: Data returned from `load` while rendering /dashboard is not serializable: Cannot stringify arbitrary non-POJOs (data.feed.parish_tax[0].parish_rate)

Here are my table columns:

companies

enter image description here

parish_tax

enter image description here

Trying to understand why I'm receiving this error, if anyone could help.

Thanks!

like image 618
cdwhiteiv Avatar asked Oct 15 '25 16:10

cdwhiteiv


1 Answers

You are supposed to only return POJOs (plain-old-javascript-objects) from the load function in SvelteKit. Your response data is not serializable, because your parish_tax objects contain an attribute parish_rate which is not a POJO and therefore non serializable. I am not sure what the exact type of the parish_rate attribute is, my guess is probably a class which can not be serialized. The solution is to simply cast this attribute to a type which is serializable before returning it from the load function.

like image 102
gurumaxi Avatar answered Oct 18 '25 06:10

gurumaxi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!