Provided by TippyEntertainment
Purpose
This skill is for one specific class of problems:
ReferenceError: Cannot access 'X' before initialization
(TDZ issues caused by let/const/class, bundlers, or circular imports).
Use this skill whenever I mention:
- “TDZ”, “temporal dead zone”.
Goal: fast, concrete fixes in the actual codebase, not generic JS theory.
Inputs you should ask for
Before proposing changes, ask for:
- Error + stack trace
- At least one full stack trace pointing to source (sourcemaps enabled).
- Relevant files
- The modules/functions mentioned in the stack (imports + top of file).
- Tooling
- Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.
If something is missing, ask targeted follow‑ups instead of guessing.
Inputs you should ask for
Before proposing changes, ask for:
- Error + stack trace
- At least one full stack trace pointing to source (sourcemaps enabled).
- Relevant files
- The modules/functions mentioned in the stack (imports + top of file).
- Tooling
- Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.
If something is missing, ask targeted follow‑ups instead of guessing.
How to think about TDZ
- TDZ happens when a
let/const/class binding is touched between scope entry and its declaration line.
Common root causes:
- Variable/function/class used before its declaration in the same file.
- Circular module imports (A imports B, B imports A, with top‑level execution).
- Exported constants that depend on other exports defined later in the same module.
Required answer format
Always answer TDZ questions using this structure:
Issue
- Short description of what is failing and in which context (dev build, prod build, tests).
- The specific TDZ cause (for example, “circular import between
store.ts and routes.ts”, or “schema used before declaration”).
File/Line
- File name(s) and approximate line/region where the problem manifests and where the fix should be applied.
Fix
- Minimal, concrete code changes to remove the TDZ, such as:
- Re‑ordering declarations.
- Breaking circular imports by extracting shared pieces.
- Moving imports/usages inside functions or factories.
Result
- Briefly state how the change removes the TDZ and what behavior to expect afterward.
Fixing strategy
- Identify the binding
- Classify the pattern
- Same‑file ordering vs circular imports vs exported constant ordering.
- Propose the smallest change that breaks the TDZ
- Prefer:
- Moving declarations above use.
- Extracting shared code into a separate module to break cycles.
- Lazy imports inside functions for rarely used paths.
- Show before/after code
- Only for affected snippets, minimal and copy‑paste‑ready.
- e.g., “Re‑run
npm run build and load /app; TDZ error should be gone. If a new symbol appears, send that stack trace next.”
Constraints
- Don’t respond with pure theory; always tie explanations to actual files and imports.
- Don’t recommend disabling minification or code‑splitting as a final fix; that’s only for temporary debugging.
- Don’t propose massive refactors; default to the smallest structural change that fixes the issue.
Example prompts this skill should handle
- “TDZ again: Cannot access 'schema' before initialization in
src/routes/app.tsx.”
- “Vite prod build: Cannot access 'ce' before initialization, stack trace attached.”
- “Jest tests fail with TDZ errors after I split my store into multiple files.”
- “How do I fix this TDZ in a circular import between
store.ts and routes.ts?”
1---2name: tdz-debugger3description: Quickly diagnose and fix JavaScript Temporal Dead Zone (TDZ) / 'Cannot access X before initialization' errors.4---5# Provided by TippyEntertainment6# https://github.com/tippyentertainment/skills.git78## Purpose910This skill is for one specific class of problems:1112> ReferenceError: Cannot access 'X' before initialization 13> (TDZ issues caused by `let`/`const`/`class`, bundlers, or circular imports).1415Use this skill whenever I mention:16- “TDZ”, “temporal dead zone”.17Goal: fast, concrete fixes in the actual codebase, not generic JS theory.18## Inputs you should ask for1920Before proposing changes, ask for:21221. **Error + stack trace**23 - At least one full stack trace pointing to source (sourcemaps enabled).242. **Relevant files**25 - The modules/functions mentioned in the stack (imports + top of file).263. **Tooling**27 - Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.2829If something is missing, ask targeted follow‑ups instead of guessing.3031---3233## Inputs you should ask for3435Before proposing changes, ask for:36371. **Error + stack trace**38 - At least one full stack trace pointing to source (sourcemaps enabled).392. **Relevant files**40 - The modules/functions mentioned in the stack (imports + top of file).413. **Tooling**42 - Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.4344If something is missing, ask targeted follow‑ups instead of guessing.4546## How to think about TDZ4748- TDZ happens when a `let`/`const`/`class` binding is touched between scope entry and its declaration line.4950Common root causes:51521. Variable/function/class used before its declaration in the same file.532. Circular module imports (A imports B, B imports A, with top‑level execution).543. Exported constants that depend on other exports defined later in the same module.5556## Required answer format5758Always answer TDZ questions using this structure:59601. **Issue**61 - Short description of what is failing and in which context (dev build, prod build, tests).62 - The specific TDZ cause (for example, “circular import between `store.ts` and `routes.ts`”, or “`schema` used before declaration”).63642. **File/Line**65 - File name(s) and approximate line/region where the problem manifests and where the fix should be applied.66673. **Fix**68 - Minimal, concrete code changes to remove the TDZ, such as:69 - Re‑ordering declarations.70 - Breaking circular imports by extracting shared pieces.71 - Moving imports/usages inside functions or factories.72734. **Result**74 - Briefly state how the change removes the TDZ and what behavior to expect afterward.7576## Fixing strategy77781. **Identify the binding**792. **Classify the pattern**80 - Same‑file ordering vs circular imports vs exported constant ordering.813. **Propose the smallest change that breaks the TDZ**82 - Prefer:83 - Moving declarations above use.84 - Extracting shared code into a separate module to break cycles.85 - Lazy imports inside functions for rarely used paths.864. **Show before/after code**87 - Only for affected snippets, minimal and copy‑paste‑ready.88 - e.g., “Re‑run `npm run build` and load `/app`; TDZ error should be gone. If a new symbol appears, send that stack trace next.”8990## Constraints9192- Don’t respond with pure theory; always tie explanations to actual files and imports.93- Don’t recommend disabling minification or code‑splitting as a final fix; that’s only for temporary debugging.94- Don’t propose massive refactors; default to the smallest structural change that fixes the issue.9596## Example prompts this skill should handle9798- “TDZ again: Cannot access 'schema' before initialization in `src/routes/app.tsx`.”99- “Vite prod build: Cannot access 'ce' before initialization, stack trace attached.”100- “Jest tests fail with TDZ errors after I split my store into multiple files.”101- “How do I fix this TDZ in a circular import between `store.ts` and `routes.ts`?”