Docs
TanStack Start

TanStack Start

Install and configure shadcn/ui for TanStack Start.

Create project

Start by creating a new TanStack Start project:

pnpm create tsrouter-app@latest my-app --template typescript --tailwind

Edit tsconfig.json file

Add the baseUrl and paths properties to the compilerOptions section of the tsconfig.json:

tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Update vite.config.ts

Add the following code to the vite.config.ts file so your app can resolve paths without error:

pnpm add -D @types/node
vite.config.ts
import path from "path"
import tailwindcss from "@tailwindcss/vite"
import { TanStackRouterVite } from "@tanstack/router-plugin/vite"
import viteReact from "@vitejs/plugin-react"
import { defineConfig } from "vite"
 
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    TanStackRouterVite({ autoCodeSplitting: true }),
    viteReact(),
    tailwindcss(),
  ],
  test: {
    globals: true,
    environment: "jsdom",
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
})

Run the CLI

Run the shadcn init command to setup your project:

pnpm dlx shadcn@canary init -d

This will create a components.json file in the root of your project and configure CSS variables inside src/styles.css.

That's it

You can now start adding components to your project.

pnpm dlx shadcn@canary add button

The command above will add the Button component to your project. You can then import it like this:

app/routes/index.tsx
import { createFileRoute } from "@tanstack/react-router"
 
import { Button } from "@/components/ui/button"
 
export const Route = createFileRoute("/")({
  component: App,
})
 
function App() {
  return (
    <div>
      <Button>Click me</Button>
    </div>
  )
}