Skip to main content
RapidDev - Software Development Agency
replit-tutorial

How to debug JavaScript errors in Replit

Replit's Preview pane includes built-in browser DevTools where you can view JavaScript errors, log output, and debug client-side code without leaving the workspace. Open the Preview pane, click the DevTools icon to access the Console tab, and use console.log statements or breakpoints to trace errors. Server-side errors appear in Replit's Console tab instead, so knowing where to look is the key to fast debugging.

What you'll learn

  • Open and use the browser DevTools Console inside Replit's Preview pane
  • Distinguish between client-side and server-side error output
  • Read JavaScript error stack traces to locate the source of bugs
  • Use console.log, console.error, and breakpoints for systematic debugging
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner9 min read12 minutesAll Replit plans (Starter, Core, Pro, Enterprise)March 2026RapidDev Engineering Team
TL;DR

Replit's Preview pane includes built-in browser DevTools where you can view JavaScript errors, log output, and debug client-side code without leaving the workspace. Open the Preview pane, click the DevTools icon to access the Console tab, and use console.log statements or breakpoints to trace errors. Server-side errors appear in Replit's Console tab instead, so knowing where to look is the key to fast debugging.

How to Debug JavaScript Errors in Replit's Browser Console

JavaScript errors in web apps can be frustrating, especially when you do not know where to look. Replit provides two separate output areas: the Console tab for server-side logs and the Preview pane's DevTools for client-side browser logs. This tutorial teaches you how to use both, add effective console.log statements, read error stack traces, and fix the most common JavaScript errors that beginners encounter in Replit.

Prerequisites

  • A Replit account (free Starter plan works)
  • A web project (HTML/CSS/JS or React) running in Replit
  • Basic understanding of JavaScript syntax

Step-by-step guide

1

Open the Preview pane and access DevTools

Click the Run button at the top of your Replit workspace to start your web app. The Preview pane opens showing your running application. Look for the DevTools icon in the Preview pane toolbar — it looks like a small wrench or console icon. Click it to open the integrated browser developer tools. The Console tab shows all client-side JavaScript output including errors, warnings, and your console.log statements. This is where browser JavaScript errors appear, not in the Replit Console tab.

Expected result: The browser DevTools panel opens inside the Preview pane, showing a Console tab with any existing JavaScript output.

2

Understand the difference between Console and Preview DevTools

Replit has two places where logs appear and beginners commonly look in the wrong one. The Console tab in the main workspace shows server-side output: anything printed by your Node.js backend, Express server, or Python Flask app. The Preview DevTools Console shows client-side output: anything from JavaScript running in the browser, including React component errors, DOM manipulation bugs, and fetch API failures. If you are debugging a frontend issue and see nothing in the Replit Console, check Preview DevTools instead.

typescript
1// This appears in Replit Console (server-side)
2console.log('Server started on port 3000');
3
4// This appears in Preview DevTools (client-side)
5// Inside a React component or browser script:
6console.log('Button clicked');

Expected result: You can correctly identify whether an error is client-side or server-side and look in the right place.

3

Add strategic console.log statements to trace errors

When you encounter an error, add console.log statements before and after the suspected line to narrow down exactly where the code fails. Log variable values, function arguments, and return values. Use console.error for errors and console.warn for warnings to visually distinguish them in the output. For objects and arrays, use console.table for a formatted view. Remove or comment out debug logs before deploying.

typescript
1// Trace a function step by step
2function fetchUserData(userId) {
3 console.log('fetchUserData called with:', userId);
4
5 if (!userId) {
6 console.error('userId is undefined or null!');
7 return null;
8 }
9
10 const url = `/api/users/${userId}`;
11 console.log('Fetching from URL:', url);
12
13 return fetch(url)
14 .then(response => {
15 console.log('Response status:', response.status);
16 return response.json();
17 })
18 .then(data => {
19 console.table(data);
20 return data;
21 })
22 .catch(error => {
23 console.error('Fetch failed:', error.message);
24 });
25}

Expected result: Your console output shows the exact flow of execution and the values of key variables, making it clear where the error occurs.

4

Read and interpret JavaScript error stack traces

When JavaScript throws an error, the browser console shows a stack trace with the error type, message, and a list of function calls that led to the error. The top line is the actual error (e.g., TypeError: Cannot read properties of undefined). Below it, each line shows a file name and line number. Click on any file reference to jump to that line in the source. Common error types are TypeError (accessing properties on undefined/null), ReferenceError (using an undeclared variable), and SyntaxError (malformed code).

typescript
1// Common error: accessing a property on undefined
2const user = undefined;
3console.log(user.name);
4// TypeError: Cannot read properties of undefined (reading 'name')
5
6// Fix: add a null check
7const user = undefined;
8console.log(user?.name ?? 'No user'); // undefined, no crash
9
10// Common error: undeclared variable
11console.log(userName);
12// ReferenceError: userName is not defined
13
14// Fix: declare the variable first
15const userName = 'Alice';
16console.log(userName);

Expected result: You can read a stack trace, identify the error type and location, and navigate to the exact line causing the issue.

5

Debug React-specific errors in the Preview Console

React applications show unique errors in the browser console. White screen with no visible error usually means a rendering crash — check the Preview DevTools Console for the React error boundary message. Common React errors include hooks called conditionally (violating the Rules of Hooks), missing key props in list rendering, and state updates on unmounted components. React errors often show two stack traces: one for the actual JavaScript error and one showing the component tree.

typescript
1// Error: Missing key prop in lists
2// Warning: Each child in a list should have a unique "key" prop
3function UserList({ users }) {
4 return (
5 <ul>
6 {users.map(user => (
7 // Wrong: no key
8 <li>{user.name}</li>
9 ))}
10 </ul>
11 );
12}
13
14// Fixed: add key prop
15function UserList({ users }) {
16 return (
17 <ul>
18 {users.map(user => (
19 <li key={user.id}>{user.name}</li>
20 ))}
21 </ul>
22 );
23}

Expected result: You can identify React-specific errors in the Preview Console and apply the correct fix for common issues like missing keys and hook violations.

6

Use the Network tab to debug API and fetch errors

Many JavaScript errors come from failed API calls. In the Preview DevTools, switch to the Network tab to see every HTTP request your app makes. Click on a failed request (shown in red) to see the status code, request headers, and response body. Common issues include 404 (wrong URL path), 500 (server error), and CORS errors (Access-Control-Allow-Origin header missing). The Network tab shows you exactly what your frontend sent and what the server returned.

typescript
1// Debug a fetch call that silently fails
2async function loadData() {
3 try {
4 const response = await fetch('/api/data');
5 console.log('Status:', response.status);
6
7 if (!response.ok) {
8 const errorText = await response.text();
9 console.error('API error:', response.status, errorText);
10 return;
11 }
12
13 const data = await response.json();
14 console.log('Data loaded:', data);
15 } catch (error) {
16 console.error('Network error:', error.message);
17 }
18}

Expected result: You can inspect failed API calls in the Network tab and see the exact status code and error message the server returned.

Complete working example

src/utils/debug.js
1// src/utils/debug.js
2// Debugging utility for Replit web projects
3// Import and use these helpers during development
4
5/**
6 * Log with timestamp and context label
7 */
8export function debugLog(label, ...args) {
9 if (process.env.NODE_ENV === 'production') return;
10 const time = new Date().toISOString().slice(11, 23);
11 console.log(`[${time}] [${label}]`, ...args);
12}
13
14/**
15 * Wrap an async function with automatic error logging
16 */
17export function withErrorLogging(fn, label = 'async') {
18 return async (...args) => {
19 try {
20 debugLog(label, 'called with', args);
21 const result = await fn(...args);
22 debugLog(label, 'returned', result);
23 return result;
24 } catch (error) {
25 console.error(`[${label}] Error:`, error.message);
26 console.error('Stack:', error.stack);
27 throw error;
28 }
29 };
30}
31
32/**
33 * Safe fetch wrapper that logs request/response details
34 */
35export async function debugFetch(url, options = {}) {
36 debugLog('fetch', `${options.method || 'GET'} ${url}`);
37 try {
38 const response = await fetch(url, options);
39 debugLog('fetch', `Status: ${response.status}`);
40 if (!response.ok) {
41 const body = await response.text();
42 console.error(`[fetch] ${response.status} Error:`, body);
43 throw new Error(`HTTP ${response.status}: ${body}`);
44 }
45 return response;
46 } catch (error) {
47 console.error('[fetch] Network error:', error.message);
48 throw error;
49 }
50}
51
52/**
53 * Log React component render with props
54 */
55export function logRender(componentName, props) {
56 if (process.env.NODE_ENV === 'production') return;
57 console.log(`[render] ${componentName}`, props);
58}

Common mistakes when debugging JavaScript errors in Replit

Why it's a problem: Looking for client-side JavaScript errors in the Replit Console tab instead of the Preview DevTools

How to avoid: Open the Preview pane, click the DevTools icon, and check the Console tab there for browser JavaScript output

Why it's a problem: Ignoring the response status when making fetch calls, leading to confusing JSON parse errors

How to avoid: Always check response.ok before calling response.json() and log the status code and error text on failure

Why it's a problem: Using console.log(object) which sometimes shows a snapshot that changes later due to reference logging

How to avoid: Use console.log(JSON.stringify(object, null, 2)) or console.table(object) to capture the value at that exact moment

Why it's a problem: Leaving dozens of console.log statements in production code that expose internal state to users

How to avoid: Create a debug utility that checks NODE_ENV and only logs in development mode

Best practices

  • Always check the Preview DevTools Console for client-side JavaScript errors, not the Replit Console tab
  • Use console.error for errors and console.warn for warnings to visually distinguish severity levels
  • Add null checks and optional chaining before accessing properties on objects that might be undefined
  • Check the Network tab in DevTools when API calls fail silently instead of guessing at the problem
  • Remove or disable debug console.log statements before deploying to production
  • Use try-catch blocks around async operations and log the actual error message in the catch block
  • Wrap React apps in an Error Boundary component to prevent white screen crashes
  • Use console.table for logging arrays and objects to see formatted, readable output

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I have a React app running in Replit and the page shows a blank white screen. The Replit Console tab shows no errors. Where should I look for the JavaScript error, and what are the most common causes of a white screen in React?

Replit Prompt

My web app has a bug where clicking a button does nothing. Add console.log statements to the button's click handler and the function it calls to trace the execution flow. Also add error handling to any fetch calls in the handler so errors are logged to the browser console.

Frequently asked questions

Client-side JavaScript errors appear in the Preview pane's DevTools Console, not in the Replit Console tab. Click the DevTools icon in the Preview toolbar to open it.

The Replit Console tab only shows server-side output from your backend code. Frontend JavaScript errors only appear in the Preview pane's browser DevTools. Open DevTools from the Preview toolbar to see client-side errors.

A white screen means React encountered an error during rendering. Open Preview DevTools Console to see the error. Common causes are accessing properties on undefined objects, hook violations, and missing imports. Add an Error Boundary to catch rendering errors gracefully.

Yes. In the Preview DevTools, go to the Sources tab and set breakpoints by clicking on line numbers. You can also add the debugger keyword directly in your JavaScript code, which pauses execution when DevTools is open.

console.log displays a string representation of values. console.dir shows an interactive list of the object's properties, which is more useful for inspecting complex objects and DOM elements.

CORS errors appear when your frontend requests a URL on a different domain. In Replit, ensure your API and frontend are in the same Repl, use relative URLs like /api/data instead of absolute URLs, and add CORS middleware to your server if calling external APIs.

Replit does not have the same integrated debugger as VS Code. For client-side code, use the Preview DevTools which includes a Console, Network tab, and Sources tab with breakpoint support. For server-side Node.js debugging, use console.log or the node --inspect flag in Shell.

Yes. For complex debugging scenarios involving multiple services, deployment-specific bugs, or hard-to-reproduce errors, RapidDev can help identify root causes and implement fixes in your Replit project.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.