-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Which project does this relate to?
Start
Describe the bug
When using TanStack Start server functions and middleware, the dev server fails with a Vite import resolution error related to an internal virtual module:
[plugin:vite:import-analysis] Failed to resolve import
"tanstack-start-injected-head-scripts:v"
from "node_modules/.pnpm/@tanstack+start-server-core@1.142.11_.../dist/esm/router-manifest.js?v=7aae4dbb".
Does the file exist?
The error points to the following code inside router-manifest.ts:
let script = `import('${startManifest.clientEntry}')`;
if (process.env.TSS_DEV_SERVER === "true") {
const { injectedHeadScripts } = await import(
"tanstack-start-injected-head-scripts:v"
);
if (injectedHeadScripts) {
script = `${injectedHeadScripts + ";"}${script}`;
}
}
Vite fails during import-analysis, as the virtual module
tanstack-start-injected-head-scripts:v is never resolved.
Your Example Website or App
https://github.com/dassayan004/tanstack-rsc
Steps to Reproduce the Bug or Issue
This happens consistently when:
- Using server functions
- Adding middleware (via createMiddleware)
- Implementing Supabase auth (login/signup) inside server functions or middleware
import { createMiddleware } from '@tanstack/react-start'
export const logMiddleware = createMiddleware({ type: 'function' }).server(
async ({ next, functionId }) => {
const now = Date.now()
const result = await next()
const duration = Date.now() - now
console.log('Server Req/Res:', { duration: `${duration}ms`, functionId })
return result
},
)
import { authMiddleware } from '@/middlewares/auth'
import { logMiddleware } from '@/middlewares/logging'
import {
AuthState,
SignInSchema,
SignUpSchema,
UserMetaSchema,
} from '@/schema/auth'
import { getSupabaseServerClient } from '@/utils/supabase'
import { createServerFn } from '@tanstack/react-start'
export const signUp = createServerFn({ method: 'POST' })
.inputValidator(SignUpSchema)
.middleware([logMiddleware])
.handler(async ({ data }) => {
const { data: userData, error } =
await getSupabaseServerClient().auth.signUp({
email: data.email,
password: data.password,
})
if (error) {
switch (error.code) {
case 'email_exists':
throw new Error('Email already exists')
case 'weak_password':
throw new Error('Your password is too weak')
default:
throw new Error(error.message)
}
}
if (userData.user) {
return userData.user.id
}
throw new Error('Something went wrong')
})
export const signIn = createServerFn({ method: 'POST' })
.inputValidator(SignInSchema)
.middleware([logMiddleware])
.handler(async ({ data }) => {
const { error } = await getSupabaseServerClient().auth.signInWithPassword({
email: data.email,
password: data.password,
})
if (error) {
return { error: error.message }
}
})
export const signOut = createServerFn()
.middleware([logMiddleware])
.handler(async () => {
await getSupabaseServerClient().auth.signOut()
})
export async function getAuthUser(): Promise<AuthState> {
const supabase = getSupabaseServerClient()
const { data } = await supabase.auth.getUser()
if (!data.user) {
return { isAuthenticated: false }
}
return {
isAuthenticated: true,
user: {
email: data.user.email,
meta: { username: data.user.user_metadata.username },
},
}
}
export const getUser = createServerFn({ method: 'GET' })
.middleware([authMiddleware])
.handler<AuthState>(({ context }) => {
return context.auth
})
export const updateUser = createServerFn()
// .middleware([logMiddleware, authMiddleware])
.inputValidator(UserMetaSchema)
.handler(async ({ data }) => {
const supabase = getSupabaseServerClient()
const { error } = await supabase.auth.updateUser({
data: { username: data.username },
})
if (error) {
throw new Error(error.message)
}
})
import { createMiddleware } from '@tanstack/react-start'
import { logMiddleware } from './logging'
import { getAuthUser } from '@/functions/auth'
export const authMiddleware = createMiddleware({ type: 'function' })
.middleware([logMiddleware])
.server(async ({ next }) => {
const auth = await getAuthUser()
// return context values to handler
return next({
context: { auth },
})
})
Expected behavior
The virtual module tanstack-start-injected-head-scripts:v should be
properly registered and resolved in Vite
Or the import should be guarded / skipped when unavailable
Using server middleware + auth should not break dev server startup
Actual Behavior
- Dev server crashes with Vite import-analysis error
- App cannot start in development mode
Notes / Suspicions
- Looks like a missing or unregistered Vite virtual module
- Possibly only triggered when server functions + middleware are enabled
- The :v suffix suggests a virtual import, but no plugin appears to provide it in this scenario
Screenshots or Videos
Platform
Start Version: 1.142.11
OS: Linux
Node: latest LTS
Package manager: pnpm
Auth: Supabase (server-side via server functions)
Additional context
I’m currently completely blocked by this issue.
- The application cannot start at all once this error appears
- The dev server crashes on startup
- It’s not possible to navigate to any page
- Removing routes, auth logic, or pages does not help once the error is triggered
I couldn’t find any documentation, issues, or articles explaining:
- what
tanstack-start-injected-head-scripts:vis - how or where it is registered
- how to disable or work around it
I tried:
- Clearing
node_modulesand Vite cache - Reinstalling dependencies
- Downgrading / upgrading TanStack Start versions
- Removing Supabase code temporarily
- Disabling middleware logic
None of these helped — once the project reaches this state, the app cannot run or recover without a full rollback.
At the moment there doesn’t seem to be any workaround or configuration option to bypass this import, which makes this a hard blocker for using server functions + middleware (especially for auth flows).
👉 Reproduction repository:
https://github.com/dassayan004/tanstack-rsc