esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

code splitting build generates "empty" source map which causes a warning on Firefox

Open hi-ogawa opened this issue 1 year ago • 2 comments

Reproduction: esbuild try Related issue on Vite: https://github.com/vitejs/vite/issues/17474

As seen in the reproduction, when code splitting build outputs an entry which only re-exports from a common chunk, it generates an "empty" source map.

  • dist/entry1.js
import {
  entry1
} from "./chunk-PTJ7TEWR.js";
export {
  entry1
};
//# sourceMappingURL=entry1.js.map
  • dist/entry1.js.map
{
  "version": 3,
  "sources": [],
  "sourcesContent": [],
  "mappings": "",
  "names": []
}

I thought this behavior seems fine, but it looks like Firefox gives a warning in devtool console https://firefox-source-docs.mozilla.org/devtools-user/debugger/source_map_errors

Source map error: No sources are declared in this source map.
Resource URL: http://localhost:5173/node_modules/.vite/deps/preact.js?v=45e47ff9
Source Map URL: preact.js.map [Learn More]

Maybe this is something Firefox should tolerate, but I tested rolldown with a similar setup and found that it doesn't generate a source map for entry1.js for this specific case https://stackblitz.com/edit/vitejs-vite-npr539?file=dist%2Frolldown%2Fentry1.js, so I thought this could be handled on esbuild similarly.

hi-ogawa avatar Oct 13 '24 03:10 hi-ogawa

Huh. That's very silly that a valid source map generates a warning. I suppose I could try to have esbuild work around this warning in Firefox. Thanks for letting me know.

evanw avatar Oct 14 '24 17:10 evanw

I'm trying to use a sourcemap lookup tool to figure out which line number the original line of code was from an error, but the lookup tool fails with these weird empty source maps. The browser shows the unmapped lines, and the tool fails. So, something isn't quite right with having empty maps.

adjenks avatar Jun 04 '25 17:06 adjenks