evanw / evanw/esbuild

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

Open
#3,945 2 comments 9 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Reproduction: [esbuild try](https://esbuild.github.io/try/#YgAwLjI0LjAAewogIGVudHJ5UG9pbnRzOiBbImVudHJ5MS5qcyIsICJlbnRyeTIuanMiXSwKICBmb3JtYXQ6ICdlc20nLAogIGJ1bmRsZTogdHJ1ZSwKICBzcGxpdHRpbmc6IHRydWUsCiAgc291cmNlbWFwOiB0cnVlLAogIG91dGRpcjogJ2Rpc3QnLAp9AGUAZW50cnkxLmpzAGV4cG9ydCBjb25zdCBlbnRyeTEgPSAiZW50cnkxIgAAZW50cnkyLmpzAGV4cG9ydCBjb25zdCBlbnRyeTIgPSAiZW50cnkyIgpleHBvcnQgeyBlbnRyeTEgfSBmcm9tICIuL2VudHJ5MS5qcyI)
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`

```js
import {
entry1
} from "./chunk-PTJ7TEWR.js";
export {
entry1
};
//# sourceMappingURL=entry1.js.map
```

- `dist/entry1.js.map`

```json
{
"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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.