[GH-ISSUE #7493] Build breaks due to duplicate declaration of getSession #19456

Closed
opened 2026-04-15 18:34:11 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @wrporter on GitHub (Jan 20, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7493

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Attempting to build a TanStack Start project, starting with Better Auth v1.14.15+ produces the following error.

ℹ Building Nitro Server (preset: node-server, compatibility date: ``)                                                                                                                                                                   nitro 9:37:18 AM

 ERROR  Error: Transform failed with 1 error:                                                                                                                                                                                            nitro 9:37:19 AM
/Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main/assets/better-auth--_ZyogbZ.js:2522:6: ERROR: The symbol "getSession" has already been declared


The symbol "getSession" has already been declared

error during build:
Error: Transform failed with 1 error:                                                                                                                                                                                                                      
/Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main/assets/better-auth--_ZyogbZ.js:2522:6: ERROR: The symbol "getSession" has already been declared                                                                                               
    at failureErrorWithLog (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:1467:15)                                                                                                                                   
    at /Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:736:50                                                                                                                                                          
    at responseCallbacks.<computed> (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:603:9)                                                                                                                            
    at handleIncomingPacket (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:658:12)                                                                                                                                   
    at Socket.readFromStdout (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:581:7)                                                                                                                                   
    at Socket.emit (node:events:508:28)                                                                                                                                                                                                                    
    at addChunk (node:internal/streams/readable:559:12)                                                                                                                                                                                                    
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)                                                                                                                                                                                 
    at Readable.push (node:internal/streams/readable:390:5)                                                                                                                                                                                                
    at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)                                                                                                                                                                                        
npm error Lifecycle script `build:tanstack-start` failed with error:
npm error code 1
npm error path /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main
npm error workspace main
npm error location /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main
npm error command failed
npm error command sh -c vite build
ERROR: "build:tanstack-start" exited with 1.

Downgrading to Better Auth v1.4.14 resolves the issue.

Current vs. Expected behavior

Build used to work and now it does not.

What version of Better Auth are you using?

1.4.15

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:56 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6041",
    "release": "25.2.0",
    "cpuCount": 16,
    "cpuModel": "Apple M4 Max",
    "totalMemory": "48.00 GB",
    "freeMemory": "5.18 GB"
  },
  "node": {
    "version": "v24.12.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.3"
    },
    {
      "name": "express",
      "version": "5.2.1"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "1.4.14",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { tanstackStartCookies } from 'better-auth/tanstack-start';
import { Redacted } from 'effect';
import { createServerOnlyFn } from '@tanstack/react-start';
import { mcp } from 'better-auth/plugins';
import { remember } from '@epic-web/remember';
import { config } from '#server/config.ts';
import { db } from '#src/lib/db.ts';

const createAuth = createServerOnlyFn(() =>
  remember('betterAuth', () =>
    betterAuth({
      baseURL: config.betterAuthUrl,
      telemetry: {
        enabled: false,
      },
      database: drizzleAdapter(db, {
        provider: 'pg',
      }),
      trustedOrigins: [config.betterAuthUrl],

      advanced: {
        database: {
          // Disable ID generation and allow the database to generate IDs.
          generateId: false,
        },
      },

      // https://www.better-auth.com/docs/integrations/tanstack#usage-tips
      plugins: [
        mcp({
          loginPage: '/sign-in',
        }),
        tanstackStartCookies(),
      ],

      // https://www.better-auth.com/docs/concepts/session-management#session-caching
      session: {
        cookieCache: {
          enabled: true,
          maxAge: 5 * 60, // 5 minutes
        },
      },

      // https://www.better-auth.com/docs/concepts/oauth
      socialProviders: {
        google: {
          prompt: 'select_account',
          clientId: Redacted.value(config.googleOauthClientId),
          clientSecret: Redacted.value(config.googleOauthClientSecret),
        },
      },

      secret: Redacted.value(config.betterAuthSecret),

      // https://www.better-auth.com/docs/authentication/email-password
      emailAndPassword: {
        enabled: true,
      },
    }),
  ),
);

export const auth = createAuth();

Additional context

No response

Originally created by @wrporter on GitHub (Jan 20, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7493 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Attempting to build a TanStack Start project, starting with Better Auth v1.14.15+ produces the following error. ``` ℹ Building Nitro Server (preset: node-server, compatibility date: ``) nitro 9:37:18 AM ERROR Error: Transform failed with 1 error: nitro 9:37:19 AM /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main/assets/better-auth--_ZyogbZ.js:2522:6: ERROR: The symbol "getSession" has already been declared The symbol "getSession" has already been declared error during build: Error: Transform failed with 1 error: /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main/assets/better-auth--_ZyogbZ.js:2522:6: ERROR: The symbol "getSession" has already been declared at failureErrorWithLog (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:1467:15) at /Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:736:50 at responseCallbacks.<computed> (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:603:9) at handleIncomingPacket (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:658:12) at Socket.readFromStdout (/Users/wesp/code/src/github.com/wrporter/commit-v2/node_modules/esbuild/lib/main.js:581:7) at Socket.emit (node:events:508:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) at Readable.push (node:internal/streams/readable:390:5) at Pipe.onStreamRead (node:internal/stream_base_commons:189:23) npm error Lifecycle script `build:tanstack-start` failed with error: npm error code 1 npm error path /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main npm error workspace main npm error location /Users/wesp/code/src/github.com/wrporter/commit-v2/apps/main npm error command failed npm error command sh -c vite build ERROR: "build:tanstack-start" exited with 1. ``` Downgrading to Better Auth v1.4.14 resolves the issue. ### Current vs. Expected behavior Build used to work and now it does not. ### What version of Better Auth are you using? 1.4.15 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:56 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6041", "release": "25.2.0", "cpuCount": 16, "cpuModel": "Apple M4 Max", "totalMemory": "48.00 GB", "freeMemory": "5.18 GB" }, "node": { "version": "v24.12.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "react", "version": "19.2.3" }, { "name": "express", "version": "5.2.1" } ], "databases": null, "betterAuth": { "version": "1.4.14", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { tanstackStartCookies } from 'better-auth/tanstack-start'; import { Redacted } from 'effect'; import { createServerOnlyFn } from '@tanstack/react-start'; import { mcp } from 'better-auth/plugins'; import { remember } from '@epic-web/remember'; import { config } from '#server/config.ts'; import { db } from '#src/lib/db.ts'; const createAuth = createServerOnlyFn(() => remember('betterAuth', () => betterAuth({ baseURL: config.betterAuthUrl, telemetry: { enabled: false, }, database: drizzleAdapter(db, { provider: 'pg', }), trustedOrigins: [config.betterAuthUrl], advanced: { database: { // Disable ID generation and allow the database to generate IDs. generateId: false, }, }, // https://www.better-auth.com/docs/integrations/tanstack#usage-tips plugins: [ mcp({ loginPage: '/sign-in', }), tanstackStartCookies(), ], // https://www.better-auth.com/docs/concepts/session-management#session-caching session: { cookieCache: { enabled: true, maxAge: 5 * 60, // 5 minutes }, }, // https://www.better-auth.com/docs/concepts/oauth socialProviders: { google: { prompt: 'select_account', clientId: Redacted.value(config.googleOauthClientId), clientSecret: Redacted.value(config.googleOauthClientSecret), }, }, secret: Redacted.value(config.betterAuthSecret), // https://www.better-auth.com/docs/authentication/email-password emailAndPassword: { enabled: true, }, }), ), ); export const auth = createAuth(); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 18:34:11 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 20, 2026):

It seems like you're encountering a build issue due to a duplicate declaration of getSession in your Better Auth setup, specifically when using version 1.4.15. It's great that downgrading to version 1.4.14 resolves the problem for you. This indicates a possible regression or bug introduced in version 1.4.15.

Here are a few troubleshooting steps you can take:

  1. Check your code for duplicate imports: Make sure that you haven’t unintentionally imported the getSession method multiple times in your files.
  2. Update dependencies: If there are any updates or patches for Better Auth, consider upgrading to see if the issue has been resolved in a newer version.
  3. Review the release notes: Sometimes, breaking changes are documented in release notes, which may provide insights into the change that introduced this issue.

If the problem persists, please open this issue in the Better Auth GitHub repository for further assistance. Tag @better-auth-agent if you would like an answer from the Agent.

In the meantime, is there anything specific you'd like to know about Better Auth or its features?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3773890526 --> @better-auth-agent[bot] commented on GitHub (Jan 20, 2026): It seems like you're encountering a build issue due to a duplicate declaration of `getSession` in your Better Auth setup, specifically when using version 1.4.15. It's great that downgrading to version 1.4.14 resolves the problem for you. This indicates a possible regression or bug introduced in version 1.4.15. Here are a few troubleshooting steps you can take: 1. **Check your code for duplicate imports**: Make sure that you haven’t unintentionally imported the `getSession` method multiple times in your files. 2. **Update dependencies**: If there are any updates or patches for Better Auth, consider upgrading to see if the issue has been resolved in a newer version. 3. **Review the release notes**: Sometimes, breaking changes are documented in release notes, which may provide insights into the change that introduced this issue. If the problem persists, please open this issue in the Better Auth GitHub repository for further assistance. Tag @better-auth-agent if you would like an answer from the Agent. In the meantime, is there anything specific you'd like to know about Better Auth or its features? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@himself65 commented on GitHub (Jan 20, 2026):

I cannot find duplicates of getSession in our codebase. It possibly because of your local setup

<!-- gh-comment-id:3774846988 --> @himself65 commented on GitHub (Jan 20, 2026): I cannot find duplicates of getSession in our codebase. It possibly because of your local setup
Author
Owner

@rowandh commented on GitHub (Jan 21, 2026):

I've bumped into this issue too after updating from 1.4.12 to 1.4.17. It seems to be an issue with @tanstack/nitro-v2-vite-plugin.

Updating to nitro/vite resolved the issue.

If you don't want to do that, you could add this to vite.config.ts:

export default defineConfig({
	ssr: {
		external: ["better-auth"],
	},
...
});
<!-- gh-comment-id:3781666252 --> @rowandh commented on GitHub (Jan 21, 2026): I've bumped into this issue too after updating from 1.4.12 to 1.4.17. It seems to be an issue with @tanstack/nitro-v2-vite-plugin. Updating to [nitro/vite](https://tanstack.com/start/latest/docs/framework/react/guide/hosting#nitro) resolved the issue. If you don't want to do that, you could add this to vite.config.ts: ``` export default defineConfig({ ssr: { external: ["better-auth"], }, ... }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19456