Mike Ross
Mike Ross
BABetter Auth
Created by Mike Ross on 4/5/2025 in #help
Better Auth + MySQL - Failing Schema Generation
Thank you for your help. I was able to fix the issue, which boils down to very basic mistake / misunderstanding. While I had tried to install the mysql2 package, I then also updated the import statement to "import {createPool } from "mysql2", which then lead to an error once again. It now works as expected.
8 replies
BABetter Auth
Created by Mike Ross on 4/5/2025 in #help
Better Auth + MySQL - Failing Schema Generation
Will do
8 replies
BABetter Auth
Created by Mike Ross on 4/5/2025 in #help
Better Auth + MySQL - Failing Schema Generation
When using the mysql2-promisepackage (https://classic.yarnpkg.com/en/package/mysql2-promise) in combination with this better-auth configuration:
import { betterAuth } from 'better-auth'
import { createPool } from 'mysql2-promise'

export const auth = betterAuth({
database: createPool({
host: 'localhost',
user: 'root',
password: '123',
database: 'Project',
port: 3306,
}),
})
import { betterAuth } from 'better-auth'
import { createPool } from 'mysql2-promise'

export const auth = betterAuth({
database: createPool({
host: 'localhost',
user: 'root',
password: '123',
database: 'Project',
port: 3306,
}),
})
I get the following error when running npx @better-auth/cli@latest generate:
2025-04-05T05:34:46.779Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. TypeError: (0 , _mysql2Promise.createPool) is not a function
at /Users/user/Documents/GitHub/Project/src/lib/auth.ts:5:43
at async Function.import (/Users/user/.npm/_npx/05eee8cc65087e98/node_modules/jiti/dist/jiti.cjs:1:199772)
at async resolveConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:346:18)
at async loadConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:146:23)
at async getConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:234:30)
at async Command.generateAction (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:643:18)
2025-04-05T05:34:46.779Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. TypeError: (0 , _mysql2Promise.createPool) is not a function
at /Users/user/Documents/GitHub/Project/src/lib/auth.ts:5:43
at async Function.import (/Users/user/.npm/_npx/05eee8cc65087e98/node_modules/jiti/dist/jiti.cjs:1:199772)
at async resolveConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:346:18)
at async loadConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:146:23)
at async getConfig (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:234:30)
at async Command.generateAction (file:///Users/user/.npm/_npx/05eee8cc65087e98/node_modules/@better-auth/cli/dist/index.mjs:643:18)
Note that the mysql database is up and running and accessible.
8 replies