Could not resolve "#tanstack-router-entry"
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, which wraps cloudflare-vite to run tanstack start. I haven't had time to create a clean reproduction but basically what seems to be happening, is that my auth service is created as an Effect.Service from effect-ts. One of the other deps coming is is my Drizzle postgres client from '@effect/sql-drizzle/Pg'.
As soon as i import import { auth } from '@repo/core/auth/handler' into server.ts or routes/api/auth/$.ts my app blows up with the error below. handler.ts imports my Runtime from effect, which has all my app dependencies, which some are required for some of the hooks that better auth calls in the Effectful Better Auth instance.
Possibly related to https://github.com/vitejs/vite/issues/20867#issuecomment-3431250189. I was seeing pre-bundling issues on later versions of vite.
The web app producing this error is a basic better-t-stack templated start app, with the only changes adding in alchemy and dropping in my auth into the server route. Everything starts up fine without the eventual better-auth dependency as described above.
Using vars defined in process.env
3:21:50 PM [vite] (client) Re-optimizing dependencies because lockfile has changed
VITE v7.0.0 ready in 1097 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ Debug: http://localhost:5173/__debug
➜ press h + enter to show help
[updating] web Updating Resource...
[skipped] web > url Skipped Resource (no changes)
[updated] web Updated Resource
Web -> http://localhost:5173/
✘ [ERROR] Could not resolve "#tanstack-router-entry"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/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/.bun/@[email protected]+b0d3c3aaff3e390a/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] Could not resolve "#tanstack-start-entry"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:32:32:
32 │ startEntry = await import("#tanstack-start-entry");
╵ ~~~~~~~~~~~~~~~~~~~~~~~
The package import "#tanstack-start-entry" is not defined in this "imports" map:
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/package.json:49:13:
49 │ "imports": {
╵ ^
You can mark the path "#tanstack-start-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] Could not resolve "tanstack-start-manifest:v"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:3:44:
3 │ ...t { tsrStartManifest } = await import("tanstack-start-manifest:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-manifest:v" 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] Could not resolve "tanstack-start-injected-head-scripts:v"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:9:49:
9 │ ...Scripts } = await import("tanstack-start-injected-head-scripts:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-injected-head-scripts:v" 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.
3:22:06 PM [vite] (ssr) error while updating dependencies:
Error: Build failed with 4 errors:
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:29:33: ERROR: Could not resolve "#tanstack-router-entry"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:32:32: ERROR: Could not resolve "#tanstack-start-entry"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:3:44: ERROR: Could not resolve "tanstack-start-manifest:v"
../../node_modules/.bun/@[email protected]+b0d3c3aaff3e390a/node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:9:49: ERROR: Could not resolve "tanstack-start-injected-head-scripts:v"
at failureErrorWithLog (/Users/am/Coding/redacted-projects/redacted/node_modules/.bun/[email protected]/node_modules/esbuild/lib/main.js:1467:15)
at /Users/am/Coding/redacted-projects/redacted/node_modules/.bun/[email protected]/node_modules/esbuild/lib/main.js:926:25
at /Users/am/Coding/redacted-projects/redacted/node_modules/.bun/[email protected]/node_modules/esbuild/lib/main.js:1345:9
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
3:22:06 PM [vite] Internal server error: There is a new version of the pre-bundle for "/Users/am/Coding/redacted-projects/redacted/apps/web/node_modules/.vite/deps_ssr/better-auth.js?v=93306dc9", a page reload is going to ask for it.
at CustomModuleRunner.cachedModule (workers/runner-worker.js:1236:20)
at request (workers/runner-worker.js:1154:83)
at null.<anonymous> (/Users/am/Coding/redacted-projects/redacted/packages/core/src/auth/setup.ts:4:1)
at Object.runInlinedModule (workers/runner-worker.js:1337:4)
at CustomModuleRunner.directRequest (workers/runner-worker.js:1208:59)
at CustomModuleRunner.cachedRequest (workers/runner-worker.js:1115:73)
at null.<anonymous> (/Users/am/Coding/redacted-projects/redacted/packages/core/src/auth/handler.ts:2:1)
at Object.runInlinedModule (workers/runner-worker.js:1337:4)
at CustomModuleRunner.directRequest (workers/runner-worker.js:1208:59)
at CustomModuleRunner.cachedRequest (workers/runner-worker.js:1115:73)
3:22:06 PM [vite] Internal server error: There is a new version of the pre-bundle for "/Users/am/Coding/redacted-projects/redacted/apps/web/node_modules/.vite/deps_ssr/better-auth.js?v=93306dc9", a page reload is going to ask for it.
at CustomModuleRunner.cachedModule (workers/runner-worker.js:1236:20)
at request (workers/runner-worker.js:1154:83)
at null.<anonymous> (/Users/am/Coding/redacted-projects/redacted/packages/core/src/auth/setup.ts:4:1)
at Object.runInlinedModule (workers/runner-worker.js:1337:4)
at CustomModuleRunner.directRequest (workers/runner-worker.js:1208:59)
at CustomModuleRunner.cachedRequest (workers/runner-worker.js:1115:73)
at null.<anonymous> (/Users/am/Coding/redacted-projects/redacted/packages/core/src/auth/handler.ts:2:1)
at Object.runInlinedModule (workers/runner-worker.js:1337:4)
at CustomModuleRunner.directRequest (workers/runner-worker.js:1208:59)
at CustomModuleRunner.cachedRequest (workers/runner-worker.js:1115:73)
Your Example Website or App
N/A
Steps to Reproduce the Bug or Issue
see above
Expected behavior
no issues
Screenshots or Videos
No response
Platform
Vite 7.0.0 MacOS 15.6 Tanstack 1.134.15
Additional context
No response
please share a full reproduction project
not op but I have the same error in this repo
https://github.com/guillemus/tanstack-mpa
This happened after I tried to add better auth. Maybe it is bc there's no entry-client / server files? That's what haiku suggested me but idk.
here's the full output:
➜ tanstack-mpa git:(main) ✗ bun dev
$ vite dev --port 3000
VITE v7.2.2 ready in 417 ms
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
➜ press h + enter to show help
✘ [ERROR] Could not resolve "#tanstack-router-entry"
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/@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] Could not resolve "#tanstack-start-entry"
node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:32:32:
32 │ startEntry = await import("#tanstack-start-entry");
╵ ~~~~~~~~~~~~~~~~~~~~~~~
The package import "#tanstack-start-entry" is not defined in this "imports" map:
node_modules/@tanstack/start-server-core/package.json:49:13:
49 │ "imports": {
╵ ^
You can mark the path "#tanstack-start-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] Could not resolve "tanstack-start-manifest:v"
node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:3:44:
3 │ const { tsrStartManifest } = await import("tanstack-start-manifest:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-manifest:v" 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] Could not resolve "tanstack-start-injected-head-scripts:v"
node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:9:49:
9 │ const { injectedHeadScripts } = await import("tanstack-start-injected-head-scripts:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-injected-head-scripts:v" 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.
/Users/guillem/Documents/projects/tanstack-mpa/node_modules/esbuild/lib/main.js:1467
let error = new Error(text);
^
Error: Error during dependency optimization:
✘ [ERROR] Could not resolve "#tanstack-router-entry"
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/@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] Could not resolve "#tanstack-start-entry"
node_modules/@tanstack/start-server-core/dist/esm/createStartHandler.js:32:32:
32 │ startEntry = await import("#tanstack-start-entry");
╵ ~~~~~~~~~~~~~~~~~~~~~~~
The package import "#tanstack-start-entry" is not defined in this "imports" map:
node_modules/@tanstack/start-server-core/package.json:49:13:
49 │ "imports": {
╵ ^
You can mark the path "#tanstack-start-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] Could not resolve "tanstack-start-manifest:v"
node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:3:44:
3 │ ...t { tsrStartManifest } = await import("tanstack-start-manifest:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-manifest:v" 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] Could not resolve "tanstack-start-injected-head-scripts:v"
node_modules/@tanstack/start-server-core/dist/esm/router-manifest.js:9:49:
9 │ ...Scripts } = await import("tanstack-start-injected-head-scripts:v");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path "tanstack-start-injected-head-scripts:v" 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.
at failureErrorWithLog (/Users/guillem/Documents/projects/tanstack-mpa/node_modules/esbuild/lib/main.js:1467:15)
at /Users/guillem/Documents/projects/tanstack-mpa/node_modules/esbuild/lib/main.js:926:25
at /Users/guillem/Documents/projects/tanstack-mpa/node_modules/esbuild/lib/main.js:1345:9
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
errors: [Getter/Setter],
warnings: [Getter/Setter]
}
Node.js v22.17.1
error: script "dev" exited with code 1
@schiller-manuel I found what causes the issue somehow.
to reproduce:
- clone the repo
- rm -rf .tanstack && bun i
- you should see the error when running
bun dev - comment out all code from counter.ts file
- bun dev should now work.
- uncomment back the code from counter.ts
- bun dev should now work with the original code.
I hope this helps
@guillemus Even adding the client/server.ts entry files, I run into the same issues as well
I have the same issue but with Vitest.
@theoludwig can you share a reproducer project with vitest?
@theoludwig can you share a reproducer project with vitest?
Sure, here it is: https://github.com/theoludwig/vite-nitro-issues/tree/vitest-issue
To reproduce:
git clone [email protected]:theoludwig/vite-nitro-issues.gitcd vite-nitro-issuesgit checkout vitest-issuepnpm install --frozen-lockfilenode --run test
I'll see if I have time to make a reproducer sometime this week, but I'm having this exact issue when I install a specific library.
better-auth@beta (since 1.4 stable is coming out Friday)
I only see this issue if I enable the reactStartCookie plugin by better-auth.
And only after removing the node_modules folder and reinstalling(pnpm install).
If I remove the plugin, clean, install. All works fine.
Maybe this observation helps..
@rollsrobby That did the trick for me!
It got me curious and looked into what could possibly be making this issue.
I was able to reproduce the original poster's issue by using setCookie imported from "@tanstack/react-start/server" (used in certain cases). I hope this narrows it down for you, @schiller-manuel
update: I guess it's mostly affects improper uses of functions that should only run on the server like setting cookies, or headers that causes the error.
@gianlazaro I ran into the same issue when using Better Auth with Tanstack Start and I can see there is already a PR open on their end to fix it by using the proper imports
https://github.com/better-auth/better-auth/pull/6045
For better-auth users this has been fixed in ^1.4.1
- https://github.com/better-auth/better-auth/pull/6209
@dotnize @2bdelghafour
1.4.1 fixed the issue but 1.4.2 (released a couple of hours ago) reverts back to importing start-server-core because it apparently fixes the cookies issue on with solid on tanstack start.
We're back to the same issue.
https://github.com/better-auth/better-auth/pull/6235
This is not a better-auth fix, the fix should be done in TanStack Start.
I'm not using better-auth and I also have the issue.
Can confirm, this issue is back. I am using better-auth though, on v1.4.2
This problem has reappeared with better-auth 1.4.2
I have the same problem when I use better-auth in the version 1.4.2
Thought v1.4.3 would resolve the issue, but it hasn't. But it does seem like this is a better-auth issue and not a Tanstack Start/Router one, so I have created an issue over there: https://github.com/better-auth/better-auth/issues/6341
Thought v1.4.3 would resolve the issue, but it hasn't. But it does seem like this is a
better-authissue and not a Tanstack Start/Router one, so I have created an issue over there: better-auth/better-auth#6341
No it is not, it can be solved in better-auth of course, with workaround, if they want to, but the root of the issue still need to be solved in TanStack Start. Also please don't spam the issues with better-auth related, it doesn't really add new information to the issue.
The issue happens, whenever, you import a module that imports import { getCookie, setCookie } from "@tanstack/react-start/server" in client, even if the getCookie or setCookie functions are not executed on the client.
TanStack Start, should make it so that it still works, even if you import getCookie/setCookie client side, as long, as it's not executed client side, and only executed server side.
@theoludwig But that's an anti-pattern. Like the path to the import clearly states, getCookie and setCookie are for server-use only. Making them isomorphic or not throwing an error if they are called on the client (if someone did this intentionally) and they receive nothing, it could also cause an issue.
Better Auth would have to implement clearer separation of concerns with the functions that are importing these server-only functions. I've seen this happen in the app I'm building as well, and I can't just add a /server import anywhere in a utils file and expect that things should still work.
For example, doing the same thing on Next.js would throw an error like this:
The issue happens, whenever, you import a module that imports
import { getCookie, setCookie } from "@tanstack/react-start/server"in client, even if thegetCookieorsetCookiefunctions are not executed on the client.TanStack Start, should make it so that it still works, even if you import
getCookie/setCookieclient side, as long, as it's not executed client side, and only executed server side.
@theoludwig I'm not sure if that's the issue with better-auth though, so I'm guessing there's more than 1 way to get this error. In better-auth's case, the error is caused by importing from @tanstack/start-server-core (to make it work for both solid and react) rather than directly from @tanstack/react-start. The fix in better-auth 1.4.1 was replacing the import with @tanstack/react-start.
But yeah this is most likely an issue with Start and not with better-auth.
My workaround was basically copying the better-auth tanstack file (and adding serverOnlyFn):
import { createServerOnlyFn } from "@tanstack/react-start";
import { BetterAuthPlugin } from "better-auth";
import { createAuthMiddleware } from "better-auth/plugins";
import { parseSetCookieHeader } from "./utils";
export const tanstackStartCookie = () =>
createServerOnlyFn(() => ({
id: "tanstack-start-cookie",
hooks: {
after: [
{
matcher() {
return true;
},
handler: createAuthMiddleware(async (ctx) => {
const returned = ctx.context.responseHeaders;
if ("_flag" in ctx && ctx._flag === "router") return;
if (returned instanceof Headers) {
const setCookies = returned?.get("set-cookie");
if (!setCookies) return;
const parsed = parseSetCookieHeader(setCookies);
const { setCookie } = await import(
"@tanstack/react-start/server"
);
parsed.forEach((value, key) => {
if (!key) return;
const opts = {
sameSite: value.samesite,
secure: value.secure,
maxAge: value["max-age"],
httpOnly: value.httponly,
domain: value.domain,
path: value.path,
} as const;
try {
setCookie(key, decodeURIComponent(value.value), opts);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_) {
/* empty */
}
});
return;
}
}),
},
],
},
}))() satisfies BetterAuthPlugin;
interface CookieAttributes {
value: string;
"max-age"?: number | undefined;
expires?: Date | undefined;
domain?: string | undefined;
path?: string | undefined;
secure?: boolean | undefined;
httponly?: boolean | undefined;
samesite?: ("strict" | "lax" | "none") | undefined;
[key: string]: unknown;
}
export function parseSetCookieHeader(
setCookie: string
): Map<string, CookieAttributes> {
const cookies = new Map<string, CookieAttributes>();
const cookieArray = setCookie.split(", ");
cookieArray.forEach((cookieString) => {
const parts = cookieString.split(";").map((part) => part.trim());
const [nameValue, ...attributes] = parts;
const [name, ...valueParts] = (nameValue || "").split("=");
const value = valueParts.join("=");
if (!name || value === undefined) {
return;
}
const attrObj: CookieAttributes = { value };
attributes.forEach((attribute) => {
const [attrName, ...attrValueParts] = attribute!.split("=");
const attrValue = attrValueParts.join("=");
const normalizedAttrName = attrName!.trim().toLowerCase();
switch (normalizedAttrName) {
case "max-age":
attrObj["max-age"] = attrValue
? parseInt(attrValue.trim(), 10)
: undefined;
break;
case "expires":
attrObj.expires = attrValue ? new Date(attrValue.trim()) : undefined;
break;
case "domain":
attrObj.domain = attrValue ? attrValue.trim() : undefined;
break;
case "path":
attrObj.path = attrValue ? attrValue.trim() : undefined;
break;
case "secure":
attrObj.secure = true;
break;
case "httponly":
attrObj.httponly = true;
break;
case "samesite":
attrObj.samesite = attrValue
? (attrValue.trim().toLowerCase() as "strict" | "lax" | "none")
: undefined;
break;
default:
// Handle any other attributes
attrObj[normalizedAttrName] = attrValue ? attrValue.trim() : true;
break;
}
});
cookies.set(name, attrObj);
});
return cookies;
}
@theoludwig But that's an anti-pattern. Like the path to the import clearly states,
getCookieandsetCookieare for server-use only. Making them isomorphic or not throwing an error if they are called on the client (if someone did this intentionally) and they receive nothing, it could also cause an issue.Better Auth would have to implement clearer separation of concerns with the functions that are importing these server-only functions. I've seen this happen in the app I'm building as well, and I can't just add a /server import anywhere in a
utilsfile and expect that things should still work.For example, doing the same thing on Next.js would throw an error like this:
This is a much better error in this case. Could not resolve "#tanstack-router-entry" does not explain what the problem is at all
reverted to 1.4.1 for now
Hello 🤓
This issue will be fixed in the next better-auth release
I was able to fix it temporarily in better-auth 1.4.3. In my case, it happened with tanstackStartCookies, and I solved it by commenting out the plugin from the better-auth config, then running "rm -rf node_modules .pnpm-lock.yaml, pnpm store prune, pnpm install", and finally uncommenting the plugin.
Can confirm this has been fixed as of 1.4.4
This issue can still be reproduced with vitest with the repo and steps provided from this reply: https://github.com/TanStack/router/issues/5795#issuecomment-3519070764
And there are no workaround to this issue.
For example, I'm doing this:
import { getClientI18n, setClientI18nLocale } from "./i18n.client.ts"
// this uses `getCookie` and `setCookie` from `@tanstack/react-start/server`
// inside handlers of `createServerFn`, because, I'm importing it, it triggers the error
// even if I try to import them dynamically (inside the handler), it throws the same error
// const { getCookie } = await import("@tanstack/react-start/server")
import { getServerI18n, setServerI18nLocale } from "./i18n.server.ts"
// later in a React Hook or Component...
const getServerFnI18n = useServerFn(getServerI18n)
const i18nQuery = useSuspenseQuery(
queryOptions({
queryKey: ["i18n"],
queryFn: shouldRunClient ? getClientI18n : getServerFnI18n,
}),
)
