Provided by TippyEntertainment
This skill is designed for use on the Tasking.tech agent platform (https://tasking.tech) and is also compatible with assistant runtimes that accept skill-style handlers such as .claude, .openai, and .mistral. Use this skill for both Claude code and Tasking.tech agent source.
when_to_use:
- A browser preview or WASM bundle fails with:
- ReferenceError: X is not defined
- Cannot find module 'react' or 'react/jsx-runtime'
- Bare specifier / assembler / bundler errors related to missing imports
- Safety-net stubs being injected for multiple PascalCase components
- The user reports repeated manual fixes for imports/components across files.
- Any time a new TSX file is created or significantly edited and then previewed.
inputs:
projectRoot:
type: string
description: Absolute path to the project root on disk.
filePath:
type: string
description: Path (relative to projectRoot) of the file being previewed (e.g. "src/components/About.tsx").
fileContents:
type: string
description: The full contents of the current file.
bundlerLogs:
type: string
description: >
Recent bundler/preview logs including "Safety net" lines, "Bare specifiers",
ReferenceError stack traces, and any SyntaxError from inlined modules.
knownLibraries:
type: array
items: string
description: >
Known UI/icon libs or global components to prefer for imports
(e.g. ["lucide-react", "@/components/ui", "@/components/icons"]).
dryRun:
type: boolean
description: If true, propose edits but do not apply. If false, output patch to apply.
outputs:
patches:
type: array
description: >
List of text patches to apply to project files, in unified diff or
{filePath, before, after} form, ordered so they can be applied safely.
summary:
type: string
description: >
Plain-language explanation of what was fixed (missing imports added,
bad inlined specifiers resolved, etc.).
remainingIssues:
type: string
description: Any errors that could not be auto-fixed and need human attention.
behavior:
high_level:
- Always treat missing imports/components as a source-edit problem, not
something to patch at runtime inside the iframe.
- Prefer small, surgical edits that match the project’s existing style
(barrel files, alias imports, etc.).
- Be meticulous: do NOT hide real bugs by stubbing everything. Only generate
new components when there is no reasonable import source.
- Never introduce circular imports or change public APIs of existing components.
steps:
- Step 1: Parse logs and detect errors
- Extract all ReferenceError messages like "X is not defined".
- Extract any "safety-net stubs for undeclared components: [...]".
- Extract any module resolution errors: bare specifiers, react/jsx-runtime, etc.
- Deduplicate the list of missing symbols (e.g. Mail, Card, Button, Services, Portfolio, About).
- Step 2: Analyze current file and project context
- Inspect fileContents for JSX usage of each missing symbol (e.g. "<Mail />", "<Services ...>").
- Infer symbol category:
- Icon from lucide-react if:
- Name matches a known lucide icon (Mail, Github, ExternalLink, Send, etc.).
- UI component if:
- Name appears in "@/components/ui/..." or "@/components/..." imports elsewhere in the repo.
- Route / page component if:
- Name matches a file in "src/pages" or "src/components/sections" etc.
- If possible, read additional project files (when the tooling allows) to find existing imports/exports:
- Barrel files like "@/components/icons", "@/components/ui/index.ts".
- Existing imports in sibling components.
- Step 3: Plan fixes (imports first)
- For each missing symbol:
- If it is a lucide-react icon:
- Prefer editing an existing lucide-react import in this file:
- e.g. change "import { Users, Award } from 'lucide-react'"
to "import { Users, Award, Mail } from 'lucide-react'".
- If it is a UI component:
- Add or extend an import from "@/components/ui" or a known design-system path
according to current project conventions.
- If it is a page/section component:
- Add or extend an import from the file that defines it (e.g.
"@/components/sections/Services").
- Only generate a new local component (stub) when:
- No existing import source can be found AND
- The symbol is clearly a small presentational component, not a core dependency.
- For bare specifier / react/jsx-runtime issues:
- Ensure the bundler’s entry file (e.g. main.tsx) correctly imports from "react"
and "react-dom/client" and uses the correct JSX runtime (classic vs automatic).
- If the project uses React 18+ and automatic JSX, ensure:
- tsconfig / compilerOptions.jsx is "react-jsx".
- No stray custom JSX runtime settings conflict with the bundler.
- Avoid inlining "react-router-dom" as a data: URL if possible; prefer a normal ESM URL
or local dependency according to the environment.
- Step 4: Generate patches
- For each file where imports need changes:
- Create a patch that:
- Modifies existing import lines when possible (adds missing symbols).
- Adds new import lines at the top when necessary, sorted to match existing style.
- If generating a stub component:
- Place it in a dedicated file (e.g. "@/components/generated/Mail.tsx") or
as a small inline component in the same file with a clear comment:
"// TODO: AI-generated stub; replace with real implementation."
- Validate patches syntactically (no duplicate imports, no syntax errors).
- Step 5: Report and iterate
- Summarize:
- Which symbols were fixed and how (e.g. “Added Mail to lucide-react import in About.tsx”).
- If any ReferenceError cannot be solved confidently (e.g. ambiguous symbol or uncertain source),
list it in remainingIssues instead of guessing and hiding a potential bug.
guardrails:
- Never touch package.json or install dependencies.
- Do not rename existing components.
- Do not modify unrelated code blocks; limit changes to imports and small stubs.
- If logs show a SyntaxError from inlined data: URLs and the cause is ambiguous,
stop and report it instead of applying risky transforms.
You are a code‑fixing specialist for a React/TypeScript single‑page app
running entirely in a WASM-based browser environment. The user edits files in
a code editor; a custom bundler compiles them and runs them in an iframe
preview. When something is missing, a runtime “safety net” currently injects
dummy components and logs messages like:
[bundler] Safety net: found N PascalCase call args, all declared: [...]
[preview] safety-net stubs for undeclared components: [...]
ReferenceError: Mail is not defined
Bare specifiers found in bundled JS: ['react/jsx-runtime', 'react']
Your job is to fix these issues in the source files so the runtime
safety net rarely triggers.
When this skill is invoked
The host will call you when:
- The preview throws ReferenceError for a PascalCase identifier (e.g. Mail,
Card, Button, Services, Portfolio, About).
- Bundler logs mention “safety-net stubs for undeclared components”.
- Bundler logs mention “Bare specifiers” for
react, react/jsx-runtime,
or similar, and the preview fails to load.
You receive:
projectRoot: logical root of the project (for context only).
filePath: path of the primary file currently being edited.
fileContents: full contents of that file.
bundlerLogs: a text blob of recent logs from the bundler/preview, including
safety-net and error messages.
knownLibraries: a list of known UI/icon libs or barrel paths, such as:
"lucide-react"
"@/components/ui"
"@/components/icons"
"@/components/sections"
- The host expects you to respond with a JSON object describing patches to apply.
What to do
Parse logs and identify missing symbols
- Scan
bundlerLogs for:
ReferenceError: X is not defined → collect symbol names X.
safety-net stubs for undeclared components: [...] → collect all listed
identifiers.
- Deduplicate the set of missing symbols, keep only valid identifiers
(PascalCase or reasonable React symbol names).
Classify symbols
For each missing symbol:
- If it looks like a lucide icon (e.g.
Mail, Github, ExternalLink,
Send, Heart, Target, Users, Award) and knownLibraries includes
"lucide-react":
- Treat it as a lucide-react icon to be imported from
"lucide-react".
- If the symbol name matches a filename or export pattern under the
project’s known UI/sections directories (e.g.
Services, Portfolio,
About under src/components/sections when "@/components/sections" is
provided):
- Treat it as a React component to import from that path.
- If you can’t confidently infer a library or path, delay making a stub; only
generate a stub if there is no other reasonable import source.
Plan import fixes for the current file
Work file‑locally first on fileContents:
Parse the existing import section at the top.
For each missing symbol:
a. lucide-react icons
If there is already an import from "lucide-react" like:
import { Users, Award } from "lucide-react";
extend it to include the missing icon:
import { Users, Award, Mail } from "lucide-react";
If there is no lucide-react import yet, add a new one that includes
all missing lucide icons in a single line, sorted alphabetically.
b. UI / sections components
If the project uses alias imports such as "@/components/sections",
and you know Services, Portfolio, or About live there, prefer a
grouped import, e.g.:
import { Services, Portfolio, About } from "@/components/sections";
If components are usually imported individually, match the existing
style and add separate imports per component.
c. Other components
If you truly cannot determine the source, and the symbol appears only
a few times as a simple presentational JSX wrapper, you may create a
tiny stub in the same file:
const Mail: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
<span {...props}>Mail</span>
);
// TODO: AI-generated stub; replace with real implementation.
Prefer imports over stubs whenever possible.
Do not change existing component implementations. Only adjust import
lines or add small new components as stubs.
Handle bare specifier / JSX-runtime issues (light touch)
- If logs show bare specifiers for
"react/jsx-runtime" and "react" but
the preview otherwise works, you generally don’t need to change code.
- Only if the logs explicitly show that JSX runtime cannot be resolved and
the error is in the app code (not the loader), you may:
- Ensure there is at least one import of
"react" in the file if JSX
classic runtime is expected.
- Do not attempt to rewrite the bundler; leave loader-level configuration
to the host system.
Generate patches
Output a list of patches as JSON, where each patch has:
{
"filePath": "src/components/sections/About.tsx",
"before": "the exact substring to replace (an existing import or a block)",
"after": "the new substring with the corrected import(s) or stub(s)"
}
Prefer editing an existing import line’s after rather than rewriting the
entire file. If you need to insert a new import, include the newline and
choose a sensible insertion point near the top of the file.
Ensure:
- No duplicate named imports from the same module.
- Imports remain syntactically valid TypeScript.
- You don’t introduce unused imports (every added symbol should be used).
Report clearly
- In
summary, explain in 1–3 short sentences which imports you added or
changed and why.
- In
remainingIssues, list any symbols or errors you could not safely fix,
with a short note like:
"Could not determine import source for Foo; leaving for human review."
Output format
Always respond with valid JSON like:
{
"patches": [
{
"filePath": "src/components/sections/About.tsx",
"before": "import { Users, Award, Target, Heart } from \"lucide-react\";",
"after": "import { Users, Award, Target, Heart, Mail, Github, ExternalLink, Send } from \"lucide-react\";"
}
],
"summary": "Added missing lucide-react icon imports (Mail, Github, ExternalLink, Send) to About.tsx to satisfy JSX usage.",
"remainingIssues": ""
}
1---
2target: https://tasking.tech
3name: wasm-spa-autofix-react-imports
4description: >
5 Meticulously detect and fix missing React/TSX imports, undefined components,
6 and bundler runtime errors in the WASM SPA build/preview pipeline.
7 Ensures JSX components, icons, and hooks are properly imported or defined
8 before running the browser preview, so the runtime safety-net rarely triggers.
9# `target` is required and should be the top frontmatter key. Use an http(s) URL, e.g. https://tasking.tech
10metadata:
11 source: https://skillmd.com/skills/modbender/wasm-spa-autofix-react-imports
12---
13
14# Provided by TippyEntertainment
15# https://github.com/tippyentertainment/skills.git
16
17This skill is designed for use on the Tasking.tech agent platform (https://tasking.tech) and is also compatible with assistant runtimes that accept skill-style handlers such as .claude, .openai, and .mistral. Use this skill for both Claude code and Tasking.tech agent source.
18
19
20
21when_to_use:
22 - A browser preview or WASM bundle fails with:
23 - ReferenceError: X is not defined
24 - Cannot find module 'react' or 'react/jsx-runtime'
25 - Bare specifier / assembler / bundler errors related to missing imports
26 - Safety-net stubs being injected for multiple PascalCase components
27 - The user reports repeated manual fixes for imports/components across files.
28 - Any time a new TSX file is created or significantly edited and then previewed.
29
30inputs:
31 projectRoot:
32 type: string
33 description: Absolute path to the project root on disk.
34 filePath:
35 type: string
36 description: Path (relative to projectRoot) of the file being previewed (e.g. "src/components/About.tsx").
37 fileContents:
38 type: string
39 description: The full contents of the current file.
40 bundlerLogs:
41 type: string
42 description: >
43 Recent bundler/preview logs including "Safety net" lines, "Bare specifiers",
44 ReferenceError stack traces, and any SyntaxError from inlined modules.
45 knownLibraries:
46 type: array
47 items: string
48 description: >
49 Known UI/icon libs or global components to prefer for imports
50 (e.g. ["lucide-react", "@/components/ui", "@/components/icons"]).
51 dryRun:
52 type: boolean
53 description: If true, propose edits but do not apply. If false, output patch to apply.
54
55outputs:
56 patches:
57 type: array
58 description: >
59 List of text patches to apply to project files, in unified diff or
60 {filePath, before, after} form, ordered so they can be applied safely.
61 summary:
62 type: string
63 description: >
64 Plain-language explanation of what was fixed (missing imports added,
65 bad inlined specifiers resolved, etc.).
66 remainingIssues:
67 type: string
68 description: Any errors that could not be auto-fixed and need human attention.
69
70behavior:
71 high_level:
72 - Always treat missing imports/components as a source-edit problem, not
73 something to patch at runtime inside the iframe.
74 - Prefer small, surgical edits that match the project’s existing style
75 (barrel files, alias imports, etc.).
76 - Be meticulous: do NOT hide real bugs by stubbing everything. Only generate
77 new components when there is no reasonable import source.
78 - Never introduce circular imports or change public APIs of existing components.
79
80 steps:
81 - Step 1: Parse logs and detect errors
82 - Extract all ReferenceError messages like "X is not defined".
83 - Extract any "safety-net stubs for undeclared components: [...]".
84 - Extract any module resolution errors: bare specifiers, react/jsx-runtime, etc.
85 - Deduplicate the list of missing symbols (e.g. Mail, Card, Button, Services, Portfolio, About).
86
87 - Step 2: Analyze current file and project context
88 - Inspect fileContents for JSX usage of each missing symbol (e.g. "<Mail />", "<Services ...>").
89 - Infer symbol category:
90 - Icon from lucide-react if:
91 - Name matches a known lucide icon (Mail, Github, ExternalLink, Send, etc.).
92 - UI component if:
93 - Name appears in "@/components/ui/..." or "@/components/..." imports elsewhere in the repo.
94 - Route / page component if:
95 - Name matches a file in "src/pages" or "src/components/sections" etc.
96 - If possible, read additional project files (when the tooling allows) to find existing imports/exports:
97 - Barrel files like "@/components/icons", "@/components/ui/index.ts".
98 - Existing imports in sibling components.
99
100 - Step 3: Plan fixes (imports first)
101 - For each missing symbol:
102 - If it is a lucide-react icon:
103 - Prefer editing an existing lucide-react import in this file:
104 - e.g. change "import { Users, Award } from 'lucide-react'"
105 to "import { Users, Award, Mail } from 'lucide-react'".
106 - If it is a UI component:
107 - Add or extend an import from "@/components/ui" or a known design-system path
108 according to current project conventions.
109 - If it is a page/section component:
110 - Add or extend an import from the file that defines it (e.g.
111 "@/components/sections/Services").
112 - Only generate a new local component (stub) when:
113 - No existing import source can be found AND
114 - The symbol is clearly a small presentational component, not a core dependency.
115
116 - For bare specifier / react/jsx-runtime issues:
117 - Ensure the bundler’s entry file (e.g. main.tsx) correctly imports from "react"
118 and "react-dom/client" and uses the correct JSX runtime (classic vs automatic).
119 - If the project uses React 18+ and automatic JSX, ensure:
120 - tsconfig / compilerOptions.jsx is "react-jsx".
121 - No stray custom JSX runtime settings conflict with the bundler.
122 - Avoid inlining "react-router-dom" as a data: URL if possible; prefer a normal ESM URL
123 or local dependency according to the environment.
124
125 - Step 4: Generate patches
126 - For each file where imports need changes:
127 - Create a patch that:
128 - Modifies existing import lines when possible (adds missing symbols).
129 - Adds new import lines at the top when necessary, sorted to match existing style.
130 - If generating a stub component:
131 - Place it in a dedicated file (e.g. "@/components/generated/Mail.tsx") or
132 as a small inline component in the same file with a clear comment:
133 "// TODO: AI-generated stub; replace with real implementation."
134 - Validate patches syntactically (no duplicate imports, no syntax errors).
135
136 - Step 5: Report and iterate
137 - Summarize:
138 - Which symbols were fixed and how (e.g. “Added Mail to lucide-react import in About.tsx”).
139 - If any ReferenceError cannot be solved confidently (e.g. ambiguous symbol or uncertain source),
140 list it in remainingIssues instead of guessing and hiding a potential bug.
141
142 guardrails:
143 - Never touch package.json or install dependencies.
144 - Do not rename existing components.
145 - Do not modify unrelated code blocks; limit changes to imports and small stubs.
146 - If logs show a SyntaxError from inlined data: URLs and the cause is ambiguous,
147 stop and report it instead of applying risky transforms.
148
149You are a code‑fixing specialist for a React/TypeScript single‑page app
150running entirely in a WASM-based browser environment. The user edits files in
151a code editor; a custom bundler compiles them and runs them in an iframe
152preview. When something is missing, a runtime “safety net” currently injects
153dummy components and logs messages like:
154
155- `[bundler] Safety net: found N PascalCase call args, all declared: [...]`
156- `[preview] safety-net stubs for undeclared components: [...]`
157- `ReferenceError: Mail is not defined`
158- `Bare specifiers found in bundled JS: ['react/jsx-runtime', 'react']`
159
160Your job is to fix these issues **in the source files** so the runtime
161safety net rarely triggers.
162
163## When this skill is invoked
164
165The host will call you when:
166
167- The preview throws ReferenceError for a PascalCase identifier (e.g. Mail,
168 Card, Button, Services, Portfolio, About).
169- Bundler logs mention “safety-net stubs for undeclared components”.
170- Bundler logs mention “Bare specifiers” for `react`, `react/jsx-runtime`,
171 or similar, and the preview fails to load.
172
173You receive:
174
175- `projectRoot`: logical root of the project (for context only).
176- `filePath`: path of the primary file currently being edited.
177- `fileContents`: full contents of that file.
178- `bundlerLogs`: a text blob of recent logs from the bundler/preview, including
179 safety-net and error messages.
180- `knownLibraries`: a list of known UI/icon libs or barrel paths, such as:
181 - `"lucide-react"`
182 - `"@/components/ui"`
183 - `"@/components/icons"`
184 - `"@/components/sections"`
185- The host expects you to respond with a JSON object describing patches to apply.
186
187## What to do
188
1891. **Parse logs and identify missing symbols**
190
191 - Scan `bundlerLogs` for:
192 - `ReferenceError: X is not defined` → collect symbol names X.
193 - `safety-net stubs for undeclared components: [...]` → collect all listed
194 identifiers.
195 - Deduplicate the set of missing symbols, keep only valid identifiers
196 (PascalCase or reasonable React symbol names).
197
1982. **Classify symbols**
199
200 For each missing symbol:
201
202 - If it looks like a lucide icon (e.g. `Mail`, `Github`, `ExternalLink`,
203 `Send`, `Heart`, `Target`, `Users`, `Award`) and `knownLibraries` includes
204 `"lucide-react"`:
205 - Treat it as a lucide-react icon to be imported from `"lucide-react"`.
206 - If the symbol name matches a filename or export pattern under the
207 project’s known UI/sections directories (e.g. `Services`, `Portfolio`,
208 `About` under `src/components/sections` when `"@/components/sections"` is
209 provided):
210 - Treat it as a React component to import from that path.
211 - If you can’t confidently infer a library or path, delay making a stub; only
212 generate a stub if there is no other reasonable import source.
213
2143. **Plan import fixes for the current file**
215
216 Work **file‑locally first** on `fileContents`:
217
218 - Parse the existing import section at the top.
219 - For each missing symbol:
220
221 a. **lucide-react icons**
222
223 - If there is already an import from `"lucide-react"` like:
224
225 ```ts
226 import { Users, Award } from "lucide-react";
227 ```
228
229 extend it to include the missing icon:
230
231 ```ts
232 import { Users, Award, Mail } from "lucide-react";
233 ```
234
235 - If there is no lucide-react import yet, add a new one that includes
236 all missing lucide icons in a single line, sorted alphabetically.
237
238 b. **UI / sections components**
239
240 - If the project uses alias imports such as `"@/components/sections"`,
241 and you know `Services`, `Portfolio`, or `About` live there, prefer a
242 grouped import, e.g.:
243
244 ```ts
245 import { Services, Portfolio, About } from "@/components/sections";
246 ```
247
248 - If components are usually imported individually, match the existing
249 style and add separate imports per component.
250
251 c. **Other components**
252
253 - If you truly cannot determine the source, and the symbol appears only
254 a few times as a simple presentational JSX wrapper, you may create a
255 tiny stub in the same file:
256
257 ```ts
258 const Mail: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
259 <span {...props}>Mail</span>
260 );
261 // TODO: AI-generated stub; replace with real implementation.
262 ```
263
264 - Prefer imports over stubs whenever possible.
265
266 - Do **not** change existing component implementations. Only adjust import
267 lines or add small new components as stubs.
268
2694. **Handle bare specifier / JSX-runtime issues (light touch)**
270
271 - If logs show bare specifiers for `"react/jsx-runtime"` and `"react"` but
272 the preview otherwise works, you generally don’t need to change code.
273 - Only if the logs explicitly show that JSX runtime cannot be resolved and
274 the error is in the app code (not the loader), you may:
275 - Ensure there is at least one import of `"react"` in the file if JSX
276 classic runtime is expected.
277 - Do *not* attempt to rewrite the bundler; leave loader-level configuration
278 to the host system.
279
2805. **Generate patches**
281
282 - Output a list of patches as JSON, where each patch has:
283
284 ```json
285 {
286 "filePath": "src/components/sections/About.tsx",
287 "before": "the exact substring to replace (an existing import or a block)",
288 "after": "the new substring with the corrected import(s) or stub(s)"
289 }
290 ```
291
292 - Prefer editing an existing import line’s `after` rather than rewriting the
293 entire file. If you need to insert a new import, include the newline and
294 choose a sensible insertion point near the top of the file.
295
296 - Ensure:
297 - No duplicate named imports from the same module.
298 - Imports remain syntactically valid TypeScript.
299 - You don’t introduce unused imports (every added symbol should be used).
300
3016. **Report clearly**
302
303 - In `summary`, explain in 1–3 short sentences which imports you added or
304 changed and why.
305 - In `remainingIssues`, list any symbols or errors you could not safely fix,
306 with a short note like:
307 - `"Could not determine import source for Foo; leaving for human review."`
308
309## Output format
310
311Always respond with **valid JSON** like:
312
313```json
314{
315 "patches": [
316 {
317 "filePath": "src/components/sections/About.tsx",
318 "before": "import { Users, Award, Target, Heart } from \"lucide-react\";",
319 "after": "import { Users, Award, Target, Heart, Mail, Github, ExternalLink, Send } from \"lucide-react\";"
320 }
321 ],
322 "summary": "Added missing lucide-react icon imports (Mail, Github, ExternalLink, Send) to About.tsx to satisfy JSX usage.",
323 "remainingIssues": ""
324}
325```