Maaz Zindani

Loading the index…

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

Firefox cannot load the .map file that a script points to

Your error

request failed with status 4042 more lines it can show

Fix it fast

Most common cause, 1 of 2

A copied or concatenated library file kept its sourceMappingURL comment

Import the library from your entry file so the bundler produces one map for the whole bundle.

Fix
// resources/js/app.js: bundle it instead of copying dist files
import 'bootstrap'

# or remove the stale comment from a copied file
sed -i.bak '/sourceMappingURL=/d' public/js/vendor.js
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Firefox prints Source map error with request failed with status 404 when a script ends in a //# sourceMappingURL comment and the server has no file at that URL. The page still works; only debugging loses the original code. Deploy the .map file, remove the stray comment, or build hidden source maps. Applies to Firefox, webpack 5.113 and Vite 8.3.

  • Applies to Firefox current release, webpack 5.113, Vite 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Compare the two URLs Firefox prints under the error. Then fetch the end of the script named as Resource URL to see the comment, and ask the server for the map it names. A library's map name (such as bootstrap.js.map) under your own bundle points to cause 1; your bundle's own name with .map added points to cause 2.

Run this first
curl -s https://example.com/js/app.js | tail -c 300 | grep -o "sourceMappingURL=.*"
curl -sI https://example.com/js/bootstrap.js.map | head -n 1

Then find the line you see in this list and open its fix:

  1. 1A copied or concatenated library file kept its sourceMappingURL commentSource Map URL names a library's map, such as bootstrap.js.map, while Resource URL is a file your build produced or copied
  2. 2The bundler writes maps, but the deploy leaves them outSource Map URL is your own bundle's name plus .map (app.js.map), the map exists in the local build folder, and it is missing on the server

What does the error look like?

  • request failed with status 404
  • Resource URL: https://example.com/js/app.js
  • Source Map URL: bootstrap.js.map

Cause 1 of 2

A copied or concatenated library file kept its sourceMappingURL comment

You seeSource Map URL names a library's map, such as bootstrap.js.map, while Resource URL is a file your build produced or copied

Check

Firefox's source map loader requests the URL from the script's comment and raises request failed with status 404 when the server answers 404. Under the source map standard, a relative URL in that comment is resolved against the script's own location. A build step that copies a library's dist file, or glues several files into one without writing a new map, leaves the library's last-line comment in place, pointing at a map that was never copied.

Check
grep -n "sourceMappingURL" public/js/*.js

Fix

Import the library from your entry file so the bundler produces one map for the whole bundle. If you must ship the copied file, copy its .map beside it, or delete the comment line from the copy.

Fix
// resources/js/app.js: bundle it instead of copying dist files
import 'bootstrap'

# or remove the stale comment from a copied file
sed -i.bak '/sourceMappingURL=/d' public/js/vendor.js

Verify

The map URL now answers 200, or the comment is gone and Firefox stops asking for it.

Verify
grep -c "sourceMappingURL" public/js/vendor.js

Confirmed by tc39.es

Did this fix it?

Cause 2 of 2

The bundler writes maps, but the deploy leaves them out

You seeSource Map URL is your own bundle's name plus .map (app.js.map), the map exists in the local build folder, and it is missing on the server

Check

webpack's source-map setting and Vite's build.sourcemap: true both write a separate .map file and add a comment that points to it. When the upload copies only .js and .css files, or the server refuses .map requests, every visitor's DevTools asks for a file that is not there. webpack's documentation also warns against letting normal users download full maps, since they expose your original code.

Check
ls dist/assets/*.map 2>/dev/null | head -n 3
curl -sI https://example.com/assets/app.js.map | head -n 1

Fix

Either upload the maps on purpose, or build hidden maps: the files are still written for your error-reporting tool, but the bundle carries no comment, so browsers never request them. Turning maps off for production also works.

Fix
// webpack.config.js
module.exports = { devtool: 'hidden-source-map' };

// vite.config.js
export default { build: { sourcemap: 'hidden' } };

Verify

After a rebuild the bundles contain no sourceMappingURL comment, so Firefox has nothing to fetch.

Verify
grep -c "sourceMappingURL" dist/assets/*.js

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • Choose one source map policy per environment: hidden maps for production error tracking, full maps on staging only.
  • Pull third-party libraries in through imports rather than copying their dist files next to your bundle.
  • Add a deploy check that requests every sourceMappingURL named in the built files and fails on a 404.

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.

Next step

Want this handled for good?

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