Debugging for AI Coders | SheCodes
Beginner 5 min read

Debugging Guide for AI Coders

Every app hits errors. The difference between getting stuck and getting unstuck isn't knowing how to code. It's knowing how to describe the problem to your AI tool. This guide teaches you how. You can also paste errors into our Error Decoder tool for a plain-English explanation.

In this chapter

  • How to read an error message without panicking
  • What to copy-paste to AI when something breaks
  • The most common errors in AI-built apps and what they mean
  • A calm step-by-step approach to fixing any bug

Don't Panic

Errors are your friends, not your enemies

Seeing a big red error message can feel scary, but here's the truth: errors are helpful. They tell you exactly what went wrong and often exactly where. A program that fails silently is far worse than one that throws a clear error.

Professional developers encounter errors every single day. The skill isn't writing perfect code. It's reading error messages carefully and knowing where to look. That's what this guide will teach you.

How to Read an Error

Every error message has the same basic parts. Once you know how to read one, you can read them all.

Example Error

TypeError: Cannot read properties of undefined (reading 'name')
  at UserCard (src/components/UserCard.tsx:12:24)
  at HomePage (src/app/page.tsx:8:5)
Error Type TypeError tells you the category. Common types: TypeError (wrong type), ReferenceError (variable doesn't exist), SyntaxError (code written wrong).
Error Message Cannot read properties of undefined is the actual explanation. This is the most important part: it tells you what went wrong in plain English.
Stack Trace UserCard.tsx:12:24 tells you the exact file and line number. The first line is where the error happened. Lines below show how you got there.

Browser DevTools

Press F12 (or Cmd+Option+I on Mac) to open DevTools. These 4 tabs are all you need to know about.

Console See errors and log messages Red messages are errors, yellow are warnings. If you see a red message, copy the whole thing and paste it to your AI tool. That's often all it needs to help you.
Elements See the structure and styling of your page Right-click anything on your page and choose 'Inspect' to see its code. Useful when you want to tell your AI tool "the button with class 'submit-btn' isn't styled right."
Network See if data requests are working or failing Look for red entries: those are failed requests. You can tell your AI tool: "The request to /api/users is returning a 500 error" and it'll know exactly what to investigate.
Application See saved data like login tokens and settings If you're having login problems, check here for stored tokens. You can tell your AI tool: "I checked the Application tab and there's no auth token stored" to help it diagnose the issue.

How to Describe Problems to Your AI Tool

The better you describe a problem, the faster your AI tool can fix it. Here are ready-to-use templates for the most common situations. Just fill in the blanks and paste them into Claude Code, Cursor, or whatever tool you use.

You see an error message

β€œI see this error: [paste the full error message]. It happens when I [describe what you were doing]. Here's the code where it happens: [paste the code].”

Example: I see this error: "TypeError: Cannot read properties of undefined (reading 'name')" in my UserCard component. It happens when I load the homepage. Here's the code: [paste UserCard.tsx].

Something looks wrong but there's no error

β€œI expected [what you wanted to happen], but instead [what actually happened]. Here's the component that should be doing this: [paste the code].”

Example: I expected the signup button to be purple, but instead it's gray. Here's my Button component: [paste code]. And here's where I use it: [paste code].

Your page is blank or not loading

β€œMy page at [URL] is showing [blank/loading forever/a white screen]. I checked the browser console (F12) and saw: [paste any errors you see]. Here's my page file: [paste code].”

Example: My page at /dashboard is showing a blank white screen. I checked the browser console and saw: "Uncaught ReferenceError: data is not defined". Here's my dashboard page: [paste code].

Something worked before but stopped working

β€œThis was working before, but now it's broken. The last thing I changed was [describe your change]. The error/problem I see now is: [describe or paste error].”

Example: My contact form was working, but now it's broken. The last thing I changed was adding email validation. Now when I submit the form, nothing happens and I see this error in the console: [paste error].

Common Next.js Errors

You will see these errors. Bookmark this page so you can look them up fast. For broader troubleshooting strategies, see our When Things Break guide.

Hydration mismatch Text content does not match server-rendered HTML What this means: Your app is showing different content when it first loads vs after it finishes loading, like a page that changes its text right after appearing.
Tell your AI tool:

β€œI'm getting a hydration mismatch error. The server-rendered HTML doesn't match what the browser produces. Can you find what's different between server and client rendering in this component and fix it?”

Module not found Module not found: Can't resolve './Compnent' What this means: Your project is trying to use a file that it can't find, usually because of a typo in the file name or the wrong folder path. Think of it like sending a letter to the wrong address.
Tell your AI tool:

β€œI'm getting a 'Module not found' error for this import: [paste the import line]. Can you check if the file name and path are correct?”

'use client' is needed You're importing a component that needs useState. It only works in a Client Component. What this means: Some code only works in the browser (like buttons you can click or forms you can type into), but your file is set up to run on the server. It's like trying to use a TV remote on a radio: wrong device.
Tell your AI tool:

β€œI'm getting an error that says I need 'use client'. Here's my component: [paste code]. Can you add 'use client' in the right place?”

Cannot read properties of undefined TypeError: Cannot read properties of undefined (reading 'name') What this means: Your code is trying to get information from something that doesn't exist yet. Imagine opening an empty box and trying to read a letter inside. There's nothing there.
Tell your AI tool:

β€œI'm getting 'Cannot read properties of undefined' on this line: [paste the line]. The variable might not have data yet. Can you add a safety check?”

404 Not Found This page could not be found What this means: Your website can't find the page you're trying to visit. It's like looking for a book on a shelf, but it's filed under the wrong letter: the file is either missing or in the wrong folder.
Tell your AI tool:

β€œI'm getting a 404 error when I go to [the URL]. Can you check that my page file is in the right folder? In Next.js, the URL path needs to match the folder structure.”

NEXT_PUBLIC_ not working Environment variable is undefined in the browser What this means: You saved a secret value (like an API key) in your settings, but your website can't see it. In Next.js, values that need to work in the browser must have a special name that starts with NEXT_PUBLIC_.
Tell your AI tool (then restart your dev server):

β€œMy environment variable isn't working in the browser. Here's what I have in my .env file: [paste the variable name]. Can you make sure it's named correctly for Next.js?”

Failed to fetch TypeError: Failed to fetch / NetworkError What this means: Your app tried to talk to another server (like getting data from a database or API) and the connection failed. It's like making a phone call and getting no answer: the other end didn't respond.
Tell your AI tool:

β€œI'm getting a 'Failed to fetch' error when my app tries to call this API: [paste the URL or API route]. Can you help me figure out why the request is failing?”

Too many re-renders Error: Too many re-renders. React limits the number of renders. What this means: Your app got stuck in an endless loop, like a dog chasing its own tail. Something in your code keeps telling the page to update, which triggers another update, which triggers another, forever.
Tell your AI tool:

β€œI'm getting 'Too many re-renders' in this component: [paste the component code]. Something is causing an infinite loop. Can you find and fix it?”

Objects are not valid as a React child Objects are not valid as a React child (found: object with keys...) What this means: You're trying to display a whole bundle of data on the page, but React can only show simple things like text and numbers, not a whole bundle at once. It's like trying to display an entire filing cabinet instead of one document.
Tell your AI tool:

β€œI'm getting 'Objects are not valid as a React child' when I try to display this data: [paste the JSX line]. Can you fix it so it shows the right property instead of the whole object?”

When to Ask for Help

Asking for help is smart, not weak. But you'll get much better answers (from AI or humans) if you try these steps first.

Before-you-ask checklist

  1. 1
    Read the error message The answer is often right there. Read the whole thing, not just the first line.
  2. 2
    Google the exact error Copy the error message (without your file paths) and paste it into Google. Add your framework name.
  3. 3
    Check the docs Next.js, React, and most libraries have great docs with common error explanations.
  4. 4
    Add console.log statements Log variables at different points to find where things go wrong.
  5. 5
    Simplify and isolate Comment out code until the error stops. The last thing you uncommented is the problem.
  6. 6
    Ask AI with full context Paste the FULL error message, the relevant code, and what you expected to happen. The more context, the better the answer.

Frequently Asked Questions

My AI tool made a change and now everything is broken. What do I do?

Don't panic! If you're using Git (and you should be), you can undo the last change. Tell your AI tool: "Undo the last change you made. It broke the app. Here's the error I'm seeing: [paste error]." If you're not using Git yet, ask your AI tool to help you set it up so you have a safety net for next time.

The error message is really long and confusing. What part matters?

Focus on the very first line: that's usually the actual error. Everything after it (the "stack trace") just shows the path the code took to get there. Copy the first 2-3 lines and paste them to your AI tool.

I fixed one error and now there's a different one. Is that normal?

Totally normal! Sometimes one error hides another. Think of it like peeling an onion: you fix the outer layer and find another underneath. Keep going, one error at a time.

My AI tool keeps suggesting the same fix and it's not working. What should I try?

Give it more context. Paste the full error (not just a summary), the complete file where the error happens, and explain what you've already tried. You can also say: "I already tried [the suggestion] and it didn't work. Here's what happened after I made that change: [describe or paste new error]."

How do I know if the problem is in my code or in something else (like my internet or a service)?

Open your browser DevTools (F12), go to the Network tab, and look for red entries. If a request to an outside service is failing, the problem might not be your code. Tell your AI tool: "The Network tab shows a [status code] error when calling [URL]."

Do I need to learn to debug 'properly' to be an AI coder?

Nope! Your main debugging skill is communicating clearly with your AI tool. The better you describe the problem (what you see, what you expected, and what changed), the faster it can fix things. That's what this guide teaches.