Skip to content

Production Source Maps #3504

@pi0

Description

@pi0

Context

  1. Node.js does not consume sourcemaps by default and should be enabled:

  2. 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 using false)
  • 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?

  1. While ideally, runtimes and providers should consume source maps by default, they don't.

  2. (not necessary) The fact that source maps point to ../src makes them harder for production consumption, as .output is 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

❌ Not passing

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions