You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: improve TanStack Start skill to reduce first-attempt build failures
Three changes to address common agent self-correction patterns:
1. Use createStart(() => ({ ... })) as the default start.ts pattern.
The generated routeTree.gen.ts imports createStart types, so a plain
object export fails type checking. createStart takes a function
returning the options, not the options directly.
2. Add Finalize section with mandatory pre-completion steps: regenerate
route tree, ensure vite-env.d.ts exists, verify the build.
3. Instruct agents to read existing start.ts before modifying, matching
the project's export style instead of rewriting from scratch.
* chore: formatting
* chore: remove unused import
**WARNING: Do NOT add middleware to `createRouter()` in `router.tsx` or `app.tsx`. That is TanStack Router (client-side only). Server middleware belongs in `start.ts` using `requestMiddleware`.**
90
90
91
-
Create or update `src/start.ts`(or `app/start.ts` for legacy):
Read the existing file first. Add `authkitMiddleware` to the existing `requestMiddleware` array (or create the array if missing). Preserve the existing export style. Do not rewrite the file from scratch.
95
94
96
-
exportdefault {
97
-
requestMiddleware: [authkitMiddleware()],
98
-
};
99
-
```
95
+
### If `start.ts` does not exist
100
96
101
-
Alternative pattern with createStart:
97
+
Create `src/start.ts` (or `app/start.ts` for legacy) using `createStart`:
1.**Named export `startInstance`** — the build plugin generates `import type { startInstance }` from this file. A `default` export will cause a build error.
111
+
2.**`createStart` takes a function** returning the options object, not the options directly. `createStart({ ... })` will fail.
112
+
112
113
### Verification Checklist
113
114
114
115
-[ ]`authkitMiddleware` imported from `@workos/authkit-tanstack-react-start`
115
-
-[ ] Middleware in `requestMiddleware` array
116
-
-[ ]File exports the config (default export or named `startInstance`)
116
+
-[ ] Middleware in `requestMiddleware` array (not `middleware`)
**Note:** Server-side `getAuth()` is preferred for most use cases.
212
213
214
+
## Finalize (REQUIRED before declaring success)
215
+
216
+
After creating/editing all files, run these steps in order. Skipping them is the most common cause of build failures.
217
+
218
+
### 1. Regenerate the route tree
219
+
220
+
Adding new route files (callback, signout, etc.) makes the existing `routeTree.gen.ts` stale. The build will fail with type errors about missing routes until it is regenerated.
221
+
222
+
```bash
223
+
pnpm build 2>/dev/null || npx tsr generate
224
+
```
225
+
226
+
The build itself triggers route tree regeneration. If it fails for other reasons, use `tsr generate` directly.
227
+
228
+
### 2. Ensure Vite type declarations exist
229
+
230
+
TanStack Start projects import CSS with `import styles from './styles.css?url'`. Without Vite's type declarations, TypeScript will error on these imports. Check if `src/vite-env.d.ts` (or `app/vite-env.d.ts`) exists — if not, create it now (before attempting the build):
231
+
232
+
```typescript
233
+
/// <referencetypes="vite/client" />
234
+
```
235
+
236
+
### 3. Verify the build
237
+
238
+
```bash
239
+
pnpm build
240
+
```
241
+
242
+
Do not skip this step. If the build fails, fix the errors before finishing. Common causes:
243
+
244
+
- Stale route tree → re-run step 1
245
+
- Missing Vite types → re-run step 2
246
+
- Wrong import paths → check package name is `@workos/authkit-tanstack-react-start`
0 commit comments