Skip to content

"require is not defined" error when using with ViteΒ #1361

@wutipong

Description

@wutipong

I'm trying to add grpc-web client into a Sveltekit-based application. Here's the page load function (in Typescript, if that matters)

export const load: PageLoad = async ({ fetch, url }) => {
    const client = new MetaServiceClient("http://localhost:9000")
    const r = await client.list(new MetaListRequest(), null)

    console.log(r)
    return {
        ok: true
    }
};

And the output is

4:46:58 AM [vite] Error when evaluating SSR module /src/lib/grpc/service_pb.js:
|- ReferenceError: require is not defined
    at eval (/home/noom/mangaweb3-frontend/src/lib/grpc/service_pb.js:15:12)
    at instantiateModule (file:///home/noom/mangaweb3-frontend/node_modules/vite/dist/node/chunks/dep-df561101.js:55974:15)

where service_pb.js is the generated js file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions