|
| 1 | +````skill |
| 2 | +--- |
| 3 | +name: dev-debug |
| 4 | +description: Debug and troubleshoot website changes using the Vite dev server. Use when a page fails to load, shows a 500 error, or looks broken after editing. |
| 5 | +--- |
| 6 | +
|
| 7 | +# Dev Debug |
| 8 | +
|
| 9 | +## When to use this skill |
| 10 | +
|
| 11 | +Use this skill whenever you are making changes to pages, components, or styles and need to verify the result in the browser — especially before running the full pre-commit check suite. |
| 12 | +
|
| 13 | +This iterative loop catches runtime errors (Sass compile errors, Svelte component errors, missing imports, broken markup) that `npm run check` and `npm run lint` do **not** catch. |
| 14 | +
|
| 15 | +## The core pattern |
| 16 | +
|
| 17 | +1. Start the dev server **once** in a background terminal |
| 18 | +2. Edit files |
| 19 | +3. After each edit, poll the dev server terminal for errors and check the HTTP status of the affected page |
| 20 | +4. Fix any errors before moving on |
| 21 | +5. Only run the full `run-checks` suite when all pages look correct |
| 22 | +
|
| 23 | +--- |
| 24 | +
|
| 25 | +## Steps |
| 26 | +
|
| 27 | +### 1. Start the dev server in the background |
| 28 | +
|
| 29 | +Start `npm run dev` as a background process so you can continue making edits while it runs: |
| 30 | +
|
| 31 | +```bash |
| 32 | +npm run dev |
| 33 | +``` |
| 34 | +
|
| 35 | +> Run this as a **background terminal** (not a blocking foreground command). The server will stay running across all your edits. Note the port it binds to — usually `5173`, but if that is in use it will try `5174`, `5175`, etc. Check the startup output. |
| 36 | +
|
| 37 | +### 2. After each file edit, check for errors |
| 38 | +
|
| 39 | +**Check the dev server terminal output** for Vite SSR errors printed after your change was hot-reloaded: |
| 40 | +
|
| 41 | +Look for lines like: |
| 42 | +
|
| 43 | +``` |
| 44 | +[vite] (ssr) Error when evaluating SSR module /src/routes/... |
| 45 | +[vite] (ssr) page reload src/routes/... ← good, means no error |
| 46 | +[500] GET /blog/your-post-slug ← bad, page failed |
| 47 | +[200] GET /blog/your-post-slug ← good |
| 48 | +``` |
| 49 | +
|
| 50 | +**Check the HTTP status** of the page you changed: |
| 51 | +
|
| 52 | +```bash |
| 53 | +curl -s -o /dev/null -w "%{http_code}" http://localhost:5173/blog/your-post-slug |
| 54 | +``` |
| 55 | +
|
| 56 | +- `200` — page loaded correctly |
| 57 | +- `500` — Vite/Svelte/Sass error; read the dev server terminal for the full message |
| 58 | +
|
| 59 | +### 3. Read the error and fix it |
| 60 | +
|
| 61 | +Vite prints the full error including file path and line number. Common errors: |
| 62 | +
|
| 63 | +#### Sass undefined mixin |
| 64 | +
|
| 65 | +``` |
| 66 | +[sass] Undefined mixin. |
| 67 | + @include bp.md { ← wrong name |
| 68 | +``` |
| 69 | +
|
| 70 | +**Fix:** Use only valid mixin names from `$lib/scss/_breakpoints.scss`: |
| 71 | +`bp.for-phone-only`, `bp.for-tablet-portrait-up`, `bp.for-tablet-portrait-down`, |
| 72 | +`bp.for-tablet-landscape-up`, `bp.for-tablet-landscape-down`, `bp.for-desktop-up`. |
| 73 | +Never invent names like `bp.md`, `bp.lg`, `bp.sm`. |
| 74 | +
|
| 75 | +#### Svelte compile error / missing import |
| 76 | +
|
| 77 | +``` |
| 78 | +Error: 'SomeComponent' is not defined |
| 79 | +``` |
| 80 | +
|
| 81 | +**Fix:** Add the missing import in the `<script>` block. |
| 82 | +
|
| 83 | +#### `$props()` / `$derived()` order error |
| 84 | +
|
| 85 | +In Svelte 5 rune-mode files, `$props()` and `$derived()` must come **before** import statements: |
| 86 | +
|
| 87 | +```svelte |
| 88 | +<script lang="ts"> |
| 89 | + let { data } = $props(); // ← must be first |
| 90 | + let currentPost = $derived(...); // ← before imports |
| 91 | + import Foo from '...'; |
| 92 | +</script> |
| 93 | +``` |
| 94 | +
|
| 95 | +#### Missing module / wrong import path |
| 96 | +
|
| 97 | +``` |
| 98 | +Cannot find module '$lib/components/...' |
| 99 | +``` |
| 100 | +
|
| 101 | +**Fix:** Check the exact component path with: |
| 102 | +
|
| 103 | +```bash |
| 104 | +find src/lib/components -name "ComponentName.svelte" |
| 105 | +``` |
| 106 | +
|
| 107 | +#### Metadata not found / post returns 404 |
| 108 | +
|
| 109 | +The `+page.server.ts` loader throws if the slug is not in `static/blogMetadata.json`. After adding or renaming a post, regenerate metadata: |
| 110 | +
|
| 111 | +```bash |
| 112 | +npx tsx scripts/generateMetadata.ts |
| 113 | +``` |
| 114 | +
|
| 115 | +Then reload the page. |
| 116 | +
|
| 117 | +### 4. Confirm the fix |
| 118 | +
|
| 119 | +After each fix, re-check: |
| 120 | +
|
| 121 | +```bash |
| 122 | +curl -s -o /dev/null -w "%{http_code}" http://localhost:5173/blog/your-post-slug |
| 123 | +``` |
| 124 | +
|
| 125 | +Expect `200`. Check the dev server output again — no new `[vite] (ssr) Error` lines should appear after the most recent page reload. |
| 126 | +
|
| 127 | +### 5. Run the full check suite when done |
| 128 | +
|
| 129 | +Once all pages load correctly, run the full quality suite before committing: |
| 130 | +
|
| 131 | +```bash |
| 132 | +npm run check # TypeScript + Svelte type checking |
| 133 | +npm run lint # Prettier format check + ESLint |
| 134 | +``` |
| 135 | +
|
| 136 | +See the `run-checks` skill for the complete pre-commit checklist. |
| 137 | +
|
| 138 | +--- |
| 139 | +
|
| 140 | +## Quick reference |
| 141 | +
|
| 142 | +| Symptom | Likely cause | Fix | |
| 143 | +|---|---|---| |
| 144 | +| HTTP 500 on a page | Sass/Svelte compile error | Read dev server terminal for details | |
| 145 | +| `Undefined mixin` | Wrong breakpoint mixin name | Use `bp.for-desktop-up` etc. | |
| 146 | +| `is not defined` | Missing import | Add import in `<script>` block | |
| 147 | +| Page loads but looks broken | Missing style rules | Compare with a working post's `<style>` block | |
| 148 | +| Post returns 404 | Metadata not regenerated | Run `npx tsx scripts/generateMetadata.ts` | |
| 149 | +| Infinite Prettier failures | File not formatted | Run `npm run format` then retry commit | |
| 150 | +
|
| 151 | +```` |
0 commit comments