Skip to content

Commit 6b935ce

Browse files
authored
fix: improve TanStack Start skill to reduce first-attempt build failures (#83)
* 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
1 parent ac7922d commit 6b935ce

2 files changed

Lines changed: 47 additions & 13 deletions

File tree

skills/workos-authkit-tanstack-start/SKILL.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,33 @@ Default redirect URI: `http://localhost:3000/api/auth/callback`
8888

8989
**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`.**
9090

91-
Create or update `src/start.ts` (or `app/start.ts` for legacy):
91+
### If `start.ts` already exists
9292

93-
```typescript
94-
import { authkitMiddleware } from '@workos/authkit-tanstack-react-start';
93+
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.
9594

96-
export default {
97-
requestMiddleware: [authkitMiddleware()],
98-
};
99-
```
95+
### If `start.ts` does not exist
10096

101-
Alternative pattern with createStart:
97+
Create `src/start.ts` (or `app/start.ts` for legacy) using `createStart`:
10298

10399
```typescript
104100
import { createStart } from '@tanstack/react-start';
105101
import { authkitMiddleware } from '@workos/authkit-tanstack-react-start';
106102

107-
export default createStart({
103+
export const startInstance = createStart(() => ({
108104
requestMiddleware: [authkitMiddleware()],
109-
});
105+
}));
110106
```
111107

108+
**Two things matter here:**
109+
110+
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+
112113
### Verification Checklist
113114

114115
- [ ] `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`)
117+
- [ ] Named export: `export const startInstance = createStart(...)` (not `export default`)
117118

118119
Verify: `grep -r "authkitMiddleware" src/ app/ 2>/dev/null`
119120

@@ -210,6 +211,40 @@ function Profile() {
210211

211212
**Note:** Server-side `getAuth()` is preferred for most use cases.
212213

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+
/// <reference types="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`
247+
213248
## Error Recovery
214249

215250
### "AuthKit middleware is not configured"

src/lib/agent-interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Uses Claude Agent SDK directly with WorkOS MCP server
44
*/
55

6-
import path from 'path';
76
import { getPackageRoot } from '../utils/paths.js';
87
import { debug, logInfo, logWarn, logError, initLogFile, getLogFilePath } from '../utils/debug.js';
98
import type { InstallerOptions } from '../utils/types.js';

0 commit comments

Comments
 (0)