Most JavaScript errors fall into a handful of patterns. Once you know the pattern, the fix is quick. Below are seven of the most common errors, what they mean, and how to fix them faster with an AI assistant like Muse’s Debug tool.
Fastest workflow: copy the error and the code around it, open Muse (Alt+Shift+L), switch to Code → Debug, paste, send.
The 60-second debugging workflow
- Copy the full error message and stack trace from the console.
- Copy the function that throws (and anything it calls, if short).
- In Muse, choose Code → Debug and set the language to JavaScript or TypeScript.
- Paste both and send. Muse explains the cause in one line and gives a fixed version.
- Ask “Write a test that would have caught this” to prevent it next time.
If the error is in a dialog or a video, capture it with Alt+Shift+S instead of copying.
7 common JavaScript errors
1. Cannot read properties of undefined (reading ‘x’)
Why it happens: You’re accessing a property on something that isn’t there yet — often data from an API that hasn’t loaded.
Typical fix: data?.items ?? []. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
2. x is not a function
Why it happens: The value isn’t the function you think it is: a typo, a wrong import, or calling a method on the wrong type.
Typical fix: check the import / typeof x. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
3. Unexpected token in JSON at position 0
Why it happens: The response isn’t JSON — usually an HTML error page or an empty body.
Typical fix: check response.ok and content-type. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
4. await is only valid in async functions
Why it happens: You used await inside a function that isn’t async.
Typical fix: mark the function async. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
5. Access to fetch has been blocked by CORS policy
Why it happens: The server doesn’t allow requests from your origin. It must send the right Access-Control-Allow-* headers.
Typical fix: fix headers on the server. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
6. Maximum call stack size exceeded
Why it happens: Infinite recursion — a function keeps calling itself, often through a setter or a re-render loop.
Typical fix: add a base case. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
7. Assignment to constant variable
Why it happens: You reassigned a const.
Typical fix: use let, or create a new variable. In Muse, paste the code and the full error into Debug to get the exact fix for your case.
Prompts that get better fixes
- “Explain the root cause first, then show the smallest fix.”
- “Here’s the stack trace and the two files involved.”
- “Is there a safer pattern for this?”
- “Rewrite with TypeScript types so this can’t happen.”
Fast or Smart?
Use Muse Fast for quick, obvious errors. Switch to Muse Smart for bugs that span several functions, async timing issues and framework-specific problems.
FAQ
Can AI fix any JavaScript error?
AI is great at common errors and explaining causes. For complex bugs, give it more context — the full error, related code and what you expected — and always test the fix.
Does Muse see my project files?
No. It sees only what you paste, capture or attach.
Does this work for TypeScript and React?
Yes. Pick TypeScript or React in the language picker for more precise answers.