bun: Couldn't read your auth config in auth.ts

[Better Auth]: [#better-auth]: Couldn't read your auth config in auth.ts. Make sure to default export your auth instance or to export as a variable named auth.
2 Replies
vitorTheDev
vitorTheDevOP3mo ago
Using bun (win11), it's impossible to get both generate and runtime to work using just whats in the docs. The issue seems to be some problem with c12 package, that does'n return an object like {default}, but instead return only the auth object itself. If you only return export default auth; it erros: - runtime: SyntaxError: Export named 'auth' not found in module 'C:\dev\backend\src\lib\auth.ts' - [#better-auth]: Couldn't read your auth config in C:\dev\backend\src\lib\auth.ts. Make sure to default export your auth instance or to export as a variable named auth. (even with --config param) - it works if I export default { auth } Not a big problem, but thought it would be good to report anyway. If you only return export const auth = ... it works both runtime and generation (but it was erroring before, also related to c12 but at runtime, maybe it was something wrong somewhere else in my code, but it's ok now) my gess is that it was related to community plugin better-auth-harmony, which uses validator.js esm, because I had to fork and add "type": "module" to validator.js to make it work with "module": "NodeNext" tsconfig, but i'm just guessing).
Ping
Ping3mo ago
Haha, yeah, I understand. I'm currently working on the BetterAuth CLI, so I know exactly what you're talking about. We use c12 to read config files, it will run the file itself, and then get the for export values. When reading our code-base, I assumed it did support default exports, but I guess not. Anyway, good job figuring it out!

Did you find this page helpful?