Vite cannot find "react" import in the npm package

I'm implementing the svelte demo in my sveltekit app as a test, and when running vite server, this error occurs:
✘ [ERROR] Could not resolve "react"

node_modules/better-auth/dist/client/react/index.mjs:3:58:
3 │ import { useRef, useCallback, useSyncExternalStore } from 'react';
╵ ~~~~~~~
✘ [ERROR] Could not resolve "react"

node_modules/better-auth/dist/client/react/index.mjs:3:58:
3 │ import { useRef, useCallback, useSyncExternalStore } from 'react';
╵ ~~~~~~~
Running Node v23
Solution:
Solved: The initial import of the library in the client was using "better-auth/react", needed to change it to "better-auth/svelte" to import the correct framework library.
Jump to solution
3 Replies
bekacru
bekacru4w ago
the svelte kit app needs a serious clean up 👀 I'd suggest just following the guide in the docs for the time being
Logan
LoganOP4w ago
I cleaned it significantly, but I’ll just give that a shot instead.
Solution
Logan
Logan4w ago
Solved: The initial import of the library in the client was using "better-auth/react", needed to change it to "better-auth/svelte" to import the correct framework library.

Did you find this page helpful?