[1.4.0-beta.21] importing `better-auth/react-start` crashes `vite dev` on a cold build

hi! first of all, thanks for all the amazing work on this library :) i was having issues doing a fresh build of my barebones tanstack start app. commenting out the reactStartCookies plugin seemed to fix it. interestingly, the issue seems to be in the actual better-auth/react-start module and not the plugin. any import of the module (that doesn't get removed by vite) causes a bunch of the following errors in the console:
Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "#tanstack-router-entry"

node_modules/.pnpm/@tanstack+start-server-core@1.136.8/node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:29:33:
29 │ routerEntry = await import("#tanstack-router-entry");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~

The package import "#tanstack-router-entry" is not defined in this "imports" map:

node_modules/.pnpm/@tanstack+start-server-core@1.136.8/node_modules/@tanstack/start-server-core/package.json:49:13:
49 │ "imports": {
╵ ^

You can mark the path "#tanstack-router-entry" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also add ".catch()" here to handle this failure at run-time instead of bundle-time.
Error: Error during dependency optimization:

✘ [ERROR] Could not resolve "#tanstack-router-entry"

node_modules/.pnpm/@tanstack+start-server-core@1.136.8/node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:29:33:
29 │ routerEntry = await import("#tanstack-router-entry");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~

The package import "#tanstack-router-entry" is not defined in this "imports" map:

node_modules/.pnpm/@tanstack+start-server-core@1.136.8/node_modules/@tanstack/start-server-core/package.json:49:13:
49 │ "imports": {
╵ ^

You can mark the path "#tanstack-router-entry" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle. You can also add ".catch()" here to handle this failure at run-time instead of bundle-time.
the same error repeats for a few modules (#tanstack-router-entry, #tanstack-start-entry, tanstack-start-manifest:v, tanstack-start-injected-head-scripts:v) as far as i can tell, tanstack-start/tanstack-router throw these obtuse errors when you try to access client-only code in server code (or vice versa) in the body of a module during build time. so i suspect it's something related to that. weirdly, it seems to happen only on a totally clean build. (i was deleting node_modules and reinstalling before each run, but i think clearing the vite cache with e.g. vite dev --force might work as well.) once i get a build working, if i comment the plugin back in, it usually works. macOS Tahoe 26.1 nodejs 25.2.0 pnpm 10.22.0 sorry that's kind of a vague report. let me know if i can give any more info!
18 Replies
bekacru
bekacru7d ago
jsut opened a pr seems like they changed the import path for setCookie try out the pr version lmk if it fixes your issue
DiamondDragon
DiamondDragon6d ago
I'll comment in the PR the correct import path @tanstack/react-start-server - i think it fixes it as now i have the error below, not sure if its related to this tanstack-start import issue Other users also reported this issue when importing better auth https://github.com/TanStack/router/issues/5795
[updating] frontend Updating Resource...
[skipped] frontend > url Skipped Resource (no changes)
[updated] frontend Updated Resource
Frontend -> http://localhost:3010/
11:53:08 PM [vite] (client) Pre-transform error: Failed to resolve import "tanstack-start-injected-head-scripts:v" from "../../node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a". Does the file exist?
Plugin: vite:import-analysis
File: /Users/am/Coding/x/node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a:22:6
7 | let script = `import('${startManifest.clientEntry}')`;
8 | if (process.env.TSS_DEV_SERVER === "true") {
9 | const { injectedHeadScripts } = await import("tanstack-start-injected-head-scripts:v");
| ^
10 | if (injectedHeadScripts) {
11 | script = `${injectedHeadScripts + ";"}${script}`;
11:53:09 PM [vite] Internal server error: Failed to resolve import "tanstack-start-injected-head-scripts:v" from "../../node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a". Does the file exist?
[updating] frontend Updating Resource...
[skipped] frontend > url Skipped Resource (no changes)
[updated] frontend Updated Resource
Frontend -> http://localhost:3010/
11:53:08 PM [vite] (client) Pre-transform error: Failed to resolve import "tanstack-start-injected-head-scripts:v" from "../../node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a". Does the file exist?
Plugin: vite:import-analysis
File: /Users/am/Coding/x/node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a:22:6
7 | let script = `import('${startManifest.clientEntry}')`;
8 | if (process.env.TSS_DEV_SERVER === "true") {
9 | const { injectedHeadScripts } = await import("tanstack-start-injected-head-scripts:v");
| ^
10 | if (injectedHeadScripts) {
11 | script = `${injectedHeadScripts + ";"}${script}`;
11:53:09 PM [vite] Internal server error: Failed to resolve import "tanstack-start-injected-head-scripts:v" from "../../node_modules/.bun/@tanstack+start-server-core@1.136.11+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js?v=ceffa31a". Does the file exist?
GitHub
Could not resolve "#tanstack-router-entry" · Issue #5795 · TanSta...
Which project does this relate to? Start Describe the bug I'm out of town this weekend but was running into this so wanted to file this bug report sooner than later. I'm using alchemy, whic...
bekacru
bekacru5d ago
can you please check now if it's the right import - cc @DiamondDragon
DiamondDragon
DiamondDragon5d ago
GitHub
feat: move react-start to tanstack-start by Bekacru · Pull Request...
Summary by cubic Fix the TanStack setCookie import by switching from "@tanstack/start-server-core" to "@tanstack/start-server" in packages/better-auth/src/integr...
andy
andyOP3d ago
thanks so much for the quick turnaround! unfortunately, i can't test the actual PR locally (issue with pnpm + git dependency + monorepo)... but i tried pnpm patch better-auth and updated the import as in the PR (@tanstack/start-server-core -> @tanstack/react-start/server). that definitely fixed it! so the PR is merged but i can't find the commit or changes in canary 🥴 might be some CI/CD weirdness that i'm missing but just wanted to flag in case there's an issue!
bekacru
bekacru3d ago
our builds were failing with the same error had to revert looking into it
hobbescodes 🐅
Experiencing similar issue with the newly released v1.4.0 as well
bekacru
bekacru3d ago
we haven't change the path as it was breaking for us on build taking a look into it
hobbescodes 🐅
Oh gotcha! Sounds good 🤝 If it helps, I tried similarly just now as above with bun patch The only diff from https://github.com/better-auth/better-auth/pull/6045/file (for tanstack start changes) is that the package.json I have locally in the patch is that the dependency changes use @tanstack/react-start/server instead of @tanstack/react-start-server. And that seems to work for me locally! The usage in integrations on that PR has the proper path to use setCookie but the deps are referencing the incorrect path
bekacru
bekacru3d ago
cc @Taesu can you look into this
Taesu
Taesu3d ago
okay 👌
Omei
Omei2d ago
I noticed in the PR, shouldn't it only be @tanstack/react-start? Isn't @tanstack/start a deprecated package that was before they supported other frameworks? nobody uses this package anymore afaik
No description
Omei
Omei2d ago
1.4 is pretty much unusable for tanstack start right now
bekacru
bekacru2d ago
could you try 1.4.1-beta.1?
hobbescodes 🐅
Nice! 1.4.1-beta.1 seems to be working for me! Appreciate the quick turn around / fixes here!
Rufis
Rufis2d ago
I am having similar issues with 1.4 as well
Omei
Omei2d ago
thanks! works great now ^1.4.1-beta.1 fixes this

Did you find this page helpful?