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---234target: https://tasking.tech5name: tdz-debugger6description: >7 Quickly diagnose and fix JavaScript Temporal Dead Zone (TDZ) / 'Cannot access X before initialization' errors.8tags:9 - javascript10 - tdz11 - bundler12 - vite13 - webpack14---1516# Provided by TippyEntertainment17# https://github.com/tippyentertainment/skills.git1819## Purpose2021This skill is for one specific class of problems:2223> ReferenceError: Cannot access 'X' before initialization 24> (TDZ issues caused by `let`/`const`/`class`, bundlers, or circular imports).2526Use this skill whenever I mention:27- “TDZ”, “temporal dead zone”.28Goal: fast, concrete fixes in the actual codebase, not generic JS theory.29## Inputs you should ask for3031Before proposing changes, ask for:32331. **Error + stack trace**34 - At least one full stack trace pointing to source (sourcemaps enabled).352. **Relevant files**36 - The modules/functions mentioned in the stack (imports + top of file).373. **Tooling**38 - Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.3940If something is missing, ask targeted follow‑ups instead of guessing.4142---4344## Inputs you should ask for4546Before proposing changes, ask for:47481. **Error + stack trace**49 - At least one full stack trace pointing to source (sourcemaps enabled).502. **Relevant files**51 - The modules/functions mentioned in the stack (imports + top of file).523. **Tooling**53 - Bundler (Vite/Webpack/Rollup), test runner (Jest/Vitest), Node/browser target.5455If something is missing, ask targeted follow‑ups instead of guessing.5657## How to think about TDZ5859- TDZ happens when a `let`/`const`/`class` binding is touched between scope entry and its declaration line.6061Common root causes:62631. Variable/function/class used before its declaration in the same file.642. Circular module imports (A imports B, B imports A, with top‑level execution).653. Exported constants that depend on other exports defined later in the same module.6667## Required answer format6869Always answer TDZ questions using this structure:70711. **Issue**72 - Short description of what is failing and in which context (dev build, prod build, tests).73 - The specific TDZ cause (for example, “circular import between `store.ts` and `routes.ts`”, or “`schema` used before declaration”).74752. **File/Line**76 - File name(s) and approximate line/region where the problem manifests and where the fix should be applied.77783. **Fix**79 - Minimal, concrete code changes to remove the TDZ, such as:80 - Re‑ordering declarations.81 - Breaking circular imports by extracting shared pieces.82 - Moving imports/usages inside functions or factories.83844. **Result**85 - Briefly state how the change removes the TDZ and what behavior to expect afterward.8687## Fixing strategy88891. **Identify the binding**902. **Classify the pattern**91 - Same‑file ordering vs circular imports vs exported constant ordering.923. **Propose the smallest change that breaks the TDZ**93 - Prefer:94 - Moving declarations above use.95 - Extracting shared code into a separate module to break cycles.96 - Lazy imports inside functions for rarely used paths.974. **Show before/after code**98 - Only for affected snippets, minimal and copy‑paste‑ready.99 - 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.”100101## Constraints102103- Don’t respond with pure theory; always tie explanations to actual files and imports.104- Don’t recommend disabling minification or code‑splitting as a final fix; that’s only for temporary debugging.105- Don’t propose massive refactors; default to the smallest structural change that fixes the issue.106107## Example prompts this skill should handle108109- “TDZ again: Cannot access 'schema' before initialization in `src/routes/app.tsx`.”110- “Vite prod build: Cannot access 'ce' before initialization, stack trace attached.”111- “Jest tests fail with TDZ errors after I split my store into multiple files.”112- “How do I fix this TDZ in a circular import between `store.ts` and `routes.ts`?”