Start with a reliable description of the bug

A minimal reproducible example, often called an MRE, is a small version of a program that still demonstrates a specific problem. It helps you separate the bug from everything happening around it. Sometimes that separation reveals the cause before you need to ask anyone for help.

Before deleting code, write down three things: what you expected, what actually happened, and the steps needed to see the difference. Include the exact error message if there is one. If the result changes from run to run, note that too; the conditions that trigger it may matter more than the code you first suspected.

Record the environment needed to reproduce the issue, such as the programming language, runtime or browser, relevant package versions, and any required settings. For a browser bug, say whether it occurs after a fresh page load or only after a particular click sequence. These details give you a baseline against which to check each smaller version.

Shrink the example one change at a time

Make a copy of the failing code so the original remains available. Then remove one piece that appears unrelated: a visual style, a helper function, an extra input, or a network request. Run the example again. If the bug remains, keep the removal. If it disappears, put that piece back and investigate why it mattered. Repeating this cycle is more dependable than rewriting the whole example from memory.

Replace large or private inputs with small, invented values that preserve the behavior. If a bug occurs while processing a long list, try a list of two items. If an API response is involved, use a small local value with the same relevant shape rather than sharing credentials or real customer data. Do not replace a string with a number merely because both look similar on screen; their types may be the point of the bug.

Work toward the smallest example that still fails, not the fewest characters at any cost. Clear variable names and a short setup step make the example easier to understand. Keep a brief record of what you removed so you can restore a necessary detail if the failure vanishes.

A small JavaScript example

Suppose a shopping-total display shows 105 when you expect 15. You can explore this example in the developer console of a modern browser with JavaScript enabled. It needs no package, server, or particular library version. If you are reporting a browser-specific problem, include the browser and version you used.

A reduced example is: const prices = [10, "5"]; const total = prices.reduce((sum, price) => sum + price, 0); console.log(total);. Running it prints 105. The useful observation is that the second value is a string. With a string operand, the plus operator joins values as text instead of producing the intended numeric total.

This example is small enough to test a possible fix: convert each input to a number before adding it, while deciding separately how the program should handle invalid input. It is also small enough to share. A larger checkout interface, its styling, and its buttons are unnecessary to demonstrate this particular result.

Make the example easy for someone else to run

A good MRE includes the code or steps, the required tools, the expected result, and the actual result. Say where to run the code: a browser console, a local file, or a project with specified dependencies. If files are required, identify which file to open or which command to run. Someone following your instructions should not have to guess which action triggers the bug.

Check the final example in a fresh session or clean copy. Your working environment might contain an unsaved change, cached data, or a variable defined by an earlier console command. If the issue occurs only in the full project, state that honestly and add back the smallest missing piece until the reduced version reproduces it again.

A minimal example is not a contest to remove every detail. Its purpose is to preserve the cause while removing distractions. Once you can explain precisely when the smaller example fails, you have a stronger starting point for fixing the bug or asking a focused question.

Back to category ↗