Next.js build error in auth client #869

Closed
opened 2026-03-13 08:08:08 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @lmelati on GitHub (Mar 18, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Install better auth in next.js project
use auth client in app directory
try execute next build

Current vs. Expected behavior

expect to build project

What version of Better Auth are you using?

1.2.4

Provide environment information

- OS: [MacOS Sequoia 15.3.1]

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

Client

Auth config (if applicable)

export const client = createAuthClient({
  baseURL: env.NEXT_PUBLIC_APP_URL,
  plugins: [stripeClient({ subscription: true })],
});

Additional context

Next build error:


./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs
Attempted import error: 'useRef' is not exported from 'react' (imported as 'useRef').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs
./src/lib/auth-client.ts

./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs
Attempted import error: 'useSyncExternalStore' is not exported from 'react' (imported as 'useSyncExternalStore').

Import trace for requested module:
./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs
./src/lib/auth-client.ts```
Originally created by @lmelati on GitHub (Mar 18, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Install better auth in next.js project use auth client in app directory try execute next build ### Current vs. Expected behavior expect to build project ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash - OS: [MacOS Sequoia 15.3.1] ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript export const client = createAuthClient({ baseURL: env.NEXT_PUBLIC_APP_URL, plugins: [stripeClient({ subscription: true })], }); ``` ### Additional context Next build error: ```Failed to compile. ./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs Attempted import error: 'useRef' is not exported from 'react' (imported as 'useRef'). Import trace for requested module: ./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs ./src/lib/auth-client.ts ./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs Attempted import error: 'useSyncExternalStore' is not exported from 'react' (imported as 'useSyncExternalStore'). Import trace for requested module: ./node_modules/.pnpm/better-auth@1.2.4_typescript@5.8.2/node_modules/better-auth/dist/client/react/index.mjs ./src/lib/auth-client.ts```
GiteaMirror added the bug label 2026-03-13 08:08:08 -05:00
Author
Owner

@JNLei commented on GitHub (Mar 19, 2025):

Which version of Next.js you are using?

@JNLei commented on GitHub (Mar 19, 2025): Which version of Next.js you are using?
Author
Owner

@lmelati commented on GitHub (Mar 19, 2025):

I'm using version 15.2.3

but I solved the problem by adding

'use client' at the top of the auth-client file

@lmelati commented on GitHub (Mar 19, 2025): I'm using version 15.2.3 but I solved the problem by adding 'use client' at the top of the auth-client file
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#869