Using the CLI in SvelteKit project

I am a bit confused since I followed the SvelteKit integration guide that recommends
import { betterAuth } from "better-auth";
import { sveltekitCookies } from "better-auth/svelte-kit";
import { getRequestEvent } from "$app/server";

export const auth = betterAuth({
// ... your config
plugins: [sveltekitCookies(getRequestEvent)],
});
import { betterAuth } from "better-auth";
import { sveltekitCookies } from "better-auth/svelte-kit";
import { getRequestEvent } from "$app/server";

export const auth = betterAuth({
// ... your config
plugins: [sveltekitCookies(getRequestEvent)],
});
but when I then try any CLI command, like pnpm dlx @better-auth/cli migrate I get an error corresponding to not being able to access the $app (since it's a SvelteKit thing?).
ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module '$app/server'
ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module '$app/server'
Any recommendations?
Solution:
I think right now the only way is just to comment out code that causes the CLI to run into issues,
Jump to solution
3 Replies
Solution
Ping
Ping2mo ago
I think right now the only way is just to comment out code that causes the CLI to run into issues,
officialankan
officialankanOP2mo ago
ok! i was thinking this too since it does not affect the CLI commands. do you want me to raise an issue in github? guess this may not be prioritized atm
Ping
Ping2mo ago
It's a known issue, no need for gh issue. Thanks though

Did you find this page helpful?