Production Source Maps
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Context
-
Node.js does not consume sourcemaps by default and should be enabled:
- CLI:
node --enable-source-maps(Node.js >= v12.12) - Environment variable:
NODE_OPTIONS="--enable-source-maps"(Node.js >=v12.12) - Runtime:
module.setSourceMapsSupport(Node.js >= 22.14) orrequire("sourcem-map-support").install(Node.js < 22.14) (catch: should be as early as possible before loading any other modules)
- CLI:
-
Nitro (v2) uses rollup and esbuild to generate production sourcemaps, which are:
- External by default (
// # sourceMappingURL=[mod].mjs.map), - Could be inlined using
sourcemap: "inline"nitro config (or completely disabled usingfalse) - Do not bundle sources (regardless of inline or external), but reference to
../src, which means src needs to be deployed for them to work.
What can we do?
-
While ideally, runtimes and providers should consume source maps by default, they don't.
- We could follow up with runtimes and deployment providers to enable sourcemap support.
- We could enable a default polyfill for modern Node.js to consume maps (>= 22.14) (https://github.com/unjs/unenv/pull/511).
-
(not necessary) The fact that source maps point to
../srcmakes them harder for production consumption, as.outputis supposed to be the only deployed directory. However, at the cost of bundling sourcemap contents into the output bundle, consumption would be much easier without needing to bundle the whole project (however, it is only necessary to log the contents of source normal tracing works, regardless)
POC
Before moving forward to enable support by default or with a flag, the effect of this idea can be replicated via Nitro config and unenv polyfill.
export default defineNitroConfig({
// Enable source map consumption by default in Node.js >= 22.14
unenv: {
// Note: currently requires unenv-nightly
polyfill: ["unenv/polyfill/source-maps"],
},
// Enable full source bundling (not required)
esbuild: {
options: {
sourcesContent: true,
},
},
rollupConfig: {
output: {
sourcemapExcludeSources: false,
},
},
});
Results
POC available on nitro-deploys
✅ Works out of the box
- Node.js
- Firebase App hosting (deploy)
- Koyeb (deploy)
- Netlify functions (deploy)
- Vercel (deploy)
- Improvement: we can enable
shouldAddSourcemapSupportfor Node.js 20 support.
- Improvement: we can enable
❌ Not passing
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the POC in nitro-deploys and the Nitro configuration shown in the issue, then inspect unenv/polyfill/source-maps and the runtime/provider results. Define whether the project should enable support by default, add a flag, or change source bundling; done means a chosen scope is implemented and the listed passing and failing deployments are rechecked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, rollup, typescript
- Domain
- backend, cloud, devops
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100