CLI cant generate using SvelteKits $app import

So i just followed the guide. when i tried generating the db things i run into ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module '$app/environment'
import { dev } from '$app/environment';
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
import { env } from '$env/dynamic/private';

if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
if (!dev && !env.DATABASE_AUTH_TOKEN) throw new Error('DATABASE_AUTH_TOKEN is not set');

const client = createClient({ url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN });
export const db = drizzle(client);
import { dev } from '$app/environment';
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
import { env } from '$env/dynamic/private';

if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');
if (!dev && !env.DATABASE_AUTH_TOKEN) throw new Error('DATABASE_AUTH_TOKEN is not set');

const client = createClient({ url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN });
export const db = drizzle(client);
not entirely sure why this dosent work in the cli? i could use vite env stuff but still weird error imo
3 Replies
bekacru
bekacru2mo ago
there is some issues with reading framework speceic imports like $app/environement. Instead you should use dotenv + process.env to get the env variables. This is only for the cli, you can revert it back ocne you generated the schema
Silvan
SilvanOP2mo ago
yop thats what i did. Did i miss it or is it mentioned in the docs?
bekacru
bekacru2mo ago
It's not mentioned in the docs I think. we should probably do that

Did you find this page helpful?