Error when generating SvelteKit tables

When running the @better-auth/cli generate command in a SvelteKit project it throws the following error 2025-04-17T14:44:42.264Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module '$env/dynamic/private' For reference, this is my src/lib/db/index.js file where the error is thrown:
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";
import * as schema from "./schema";
import { env } from "$env/dynamic/private";

const client = createClient({
url: env.TURSO_DATABASE_URL,
authToken: env.TURSO_AUTH_TOKEN,
});

export const db = drizzle(client, { schema });
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";
import * as schema from "./schema";
import { env } from "$env/dynamic/private";

const client = createClient({
url: env.TURSO_DATABASE_URL,
authToken: env.TURSO_AUTH_TOKEN,
});

export const db = drizzle(client, { schema });
Thanks in advance!
5 Replies
Ping
Ping2w ago
$env/dynamic/private isn't a valid. Are you able to change that to a relative path?
realguse
realguseOP2w ago
It’s for importing env variables in svelte. So unfortunately no I think
Ping
Ping2w ago
I'm not sure you can do much else about this then. Maybe we'd have to have custom integration support for this to work? @bekacru
realguse
realguseOP2w ago
Yeah, to generate the schema I just temporarily moved everything to auth.js so it didn't have to import anything
Henry
Henry2w ago
can you import the variables directly with dynamic i.e: import {TURSO_DATABASE_URL} from "$env/dynamic/private";? Then url: TURSO_DATABASE_URL. This works for me, but I am using $env/static/private, not sure if thats different.

Did you find this page helpful?