S
SolidJS16mo ago
oneiro

What's the best way to debug `Buffer is not defined`

Hey folks, I am currently trying to re-restructure my code a bit, so it becomes more maintainable. One thing I noticed, is that I sometimes receive a Buffer is not defined runtime error inside the browser when moving things. This happened for example, when I accidentally put a module inside one of my routes sub-directories which wasn't a module and just contained some stuff to be consumed. However I also seem to get the issue, when I export server-specific functions in various places. Generally there seem to be various sources leading to this error. Is there a good way to debug this and to make finding the cause of the issue easier than carefully reading my code and using trial and error? Thanks in advance!
1 Reply
oneiro
oneiroOP16mo ago
For example: I have a file src/pages/myPage/routeData.ts. This looks like this:
import { RouteDataArgs } from "solid-start";
import { createServerData$ } from "solid-start/server";

export function routeData({ params }: RouteDataArgs) {
return createServerData$(getRouteData, { key: () => params.country });
}

export async function getRouteData(countryCode: string) {
// ... do stuff (access database etc.
return {
// ... some data
};
}
import { RouteDataArgs } from "solid-start";
import { createServerData$ } from "solid-start/server";

export function routeData({ params }: RouteDataArgs) {
return createServerData$(getRouteData, { key: () => params.country });
}

export async function getRouteData(countryCode: string) {
// ... do stuff (access database etc.
return {
// ... some data
};
}
The reason for this is, because I want to integration test getRouteData in isolation. Inside my src/routes/myPage.tsx I export route data like this:
// ...imports
export { routeData } from '~/pages/myPage/routeData.ts`
// ...imports
export { routeData } from '~/pages/myPage/routeData.ts`
Now here's the issue: 1. when I do it the way I described, I receive the Buffer is not defined issue 2. when I move routeData into the src/routes/myPage.tsx file it works correctly 3. when I instead move the getRouteData-function into routeData() as arrow function it also works 2. Is not a good option, because when I want to get the typing when using useRouteData inside subcomponents I would create a circular dependency between the route and its sub-components. This is why I want to move routeData out of the route in the first place 3. is not a good option, because I loose the ability to integration test my server side logic without running the solid-start server. Moving getRouteData into its own file does seem to solve the issue. Though I do not understand, why that is.
Want results from more Discord servers?
Add your server