T
TanStack12mo ago
adverse-sapphire

Redirects not working as shown in Start docs

I'm following this page: https://tanstack.com/router/latest/docs/framework/react/start/server-functions#redirects It includes this code for redirects:
import { createServerFn, redirect } from '@tanstack/start'

export const doStuff = createServerFn('GET', async () => {
// Redirect the user to the home page
throw redirect({
to: '/',
})
})
import { createServerFn, redirect } from '@tanstack/start'

export const doStuff = createServerFn('GET', async () => {
// Redirect the user to the home page
throw redirect({
to: '/',
})
})
However, that gives the error Module has no exported member redirect .. I can instead import redirect from @tanstack/react-router.
The code then works, but I get a TS error:
Property 'search' is missing in type '{ to: "/"; }' but required in type 'MakeRequiredSearchParams<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, Record<...>, Record<...>>, string, "/">'.ts(2345)
Property 'search' is missing in type '{ to: "/"; }' but required in type 'MakeRequiredSearchParams<Router<RootRoute<undefined, {}, AnyContext, AnyContext, {}, undefined, RootRouteChildren, FileRouteTypes>, TrailingSlashOption, Record<...>, Record<...>>, string, "/">'.ts(2345)
Since it's working I'm ok for now, but I'm wondering which is correct... is there supposed to be a redirect function in ts/start that differs from the one in ts/react-router? Here are my deps in case it helps answer:
"dependencies": {
"@clerk/tanstack-start": "^0.4.0",
"@tanstack/react-router": "^1.57.13",
"@tanstack/start": "^1.57.13",
"@vitejs/plugin-react": "^4.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vinxi": "^0.4.3"
},
"devDependencies": {
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
"dependencies": {
"@clerk/tanstack-start": "^0.4.0",
"@tanstack/react-router": "^1.57.13",
"@tanstack/start": "^1.57.13",
"@vitejs/plugin-react": "^4.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vinxi": "^0.4.3"
},
"devDependencies": {
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
7 Replies
correct-apricot
correct-apricot12mo ago
That's our bad. We'll fix the docs. redirect is exported by @tanstack/react-router
adverse-sapphire
adverse-sapphireOP12mo ago
Ok, thanks for confirming @Sean Cassiere! Any thoughts on why I'm getting the TS error I mentioned? This is my server function (based on Clerk docs for Start):
const authStateFn = createServerFn('GET', async () => {
const request = getWebRequest()
const { userId } = await getAuth(request)

if (!userId) {
throw redirect({
to: '/',
})
}

return { userId }
})
const authStateFn = createServerFn('GET', async () => {
const request = getWebRequest()
const { userId } = await getAuth(request)

if (!userId) {
throw redirect({
to: '/',
})
}

return { userId }
})
The to: '/' gets underlined looking for a "search" property that doesn't seem to exist. This code works as-is though, and the redirect to "/" functions as expected... the file's just red showing an error. I've tried things like rerunning the app, restarting the TS server, changing to the workspace version of TS, restarting VS Code, deleting node_modules, etc. Not sure what it could be since it looks ok to me and works as expected.
adverse-sapphire
adverse-sapphireOP12mo ago
Pic of the full message
No description
adverse-sapphire
adverse-sapphireOP12mo ago
And when I run the code and try to visit the route with the auth check the redirect runs correctly... here's the server console output:
ServerFn Response: 200
- Payload: {"to":"/","isRedirect":true,"statusCode":307}
ServerFn Response: 200
- Payload: {"to":"/","isRedirect":true,"statusCode":307}
there are quite a few 'conflicting' and 'could not resolve' errors/warnings when running 'npm i' on the basic TS Start app, so the error might be coming from a mismatch related to that
correct-apricot
correct-apricot12mo ago
Does your index route expect search params? Either ways, upgrade to latest
adverse-sapphire
adverse-sapphireOP12mo ago
No search params, although I will double-check my setup (just copied the quickstart docs though). I’ll also play with versions, although ‘npm outdated’ doesn’t list anything. No worries right now since Start is Alpha and it’s functional, just thought there might be something obvious I missed.
correct-apricot
correct-apricot12mo ago
It is possible that its a version mismatch, since its working fine in the examples

Did you find this page helpful?