Browser devtools show bundled code instead of my original files
Devtools show bundle.js or main.js instead of the original source filesShort 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.
Fix it fast
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.js2Match what you see, then jump to its fix
- 1
No .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
Devtools 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
- 1
What does the error look like?
Devtools show bundle.js or main.js instead of the original source filesBreakpoints stop on the wrong line in the transpiled codeNo 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/*.map2Fix
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/*.mapConfirmed by webpack.js.org
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.js2Fix
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 developmentConfirmed by webpack.js.org
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix