Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Browser devtools show bundled code instead of my original files

ErrorDevtools show bundle.js or main.js instead of the original source files

Short answer

Source maps in webpack are controlled by one option, devtool. In production it is off by default, so devtools show the bundle. In development the default eval shows transpiled code with wrong line numbers. Set eval-source-map for development and source-map for production, then rebuild.

  • Applies to webpack 5, Node.js 22, Chrome devtools
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print which devtool value the build really uses, then compare it with the two causes below.

    grep -n "devtool\|mode" webpack.config.js
  2. 2Match what you see, then jump to its fix

    1. 1No .map file appears in the output folder and devtools list only the bundleNo source map is emitted (devtool is false or unset in production)Fix
    2. 2Devtools do show a file, but breakpoints and line numbers match the transpiled output, not what you wroteDevelopment builds use eval, which maps to transpiled codeFix

What does the error look like?

  • Devtools show bundle.js or main.js instead of the original source files
  • Breakpoints stop on the wrong line in the transpiled code
  • No source map is emitted next to the bundle

Cause 1 of 2

No source map is emitted (devtool is false or unset in production)

1Check

The default for devtool is false, and in production mode webpack emits no source map unless you ask for one. Check that the config sets it and that mode is not overriding your expectation.

grep -n "devtool" webpack.config.js
ls dist/*.map

2Fix

Set devtool to source-map, which webpack recommends for production builds. It writes a separate .map file and adds a reference comment to the bundle.

// webpack.config.js
module.exports = {
  mode: 'production',
  devtool: 'source-map',
};

3Verify

Rebuild and confirm a .map file now sits next to each bundle.

npx webpack
ls dist/*.map

Confirmed by webpack.js.org

Did this fix it?

Cause 2 of 2

Development builds use eval, which maps to transpiled code

1Check

In development mode the default is eval. The webpack docs say its drawback is that line numbers are not displayed correctly, because it maps to transpiled code instead of the original.

grep -n "devtool\|mode" webpack.config.js

2Fix

Use eval-source-map in development. Rebuilds stay acceptable and line numbers map to the original code.

// webpack.config.js
module.exports = {
  mode: 'development',
  devtool: 'eval-source-map',
};

3Verify

Restart the dev build, hard-reload the page and set a breakpoint in your own file.

npx webpack --mode development

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • Set devtool explicitly in both the development and the production config instead of relying on the mode default.
  • Do not serve .map files to normal users on a public site; use hidden-source-map and upload the maps to your error tracker.
  • Keep the devtool value in the config file, not in a one-off CLI flag nobody remembers.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.