Skip to content

remove absolute file paths embedded in sourcemaps generated by SourceMapPlugin #1518

Open

Description

@mjames-c

Description

When building without a dev server (e.g. a release bundle built in CI), SourceMapPlugin names every module in the source map's sources by its absolute path on the build machine, and there's no way to override this.

} else {
moduleFilenameTemplateHandler = (info: ModuleFilenameTemplateFnCtx) =>
defaultModuleFilenameTemplateHandler('', info);
}

RepackPlugin always applies SourceMapPlugin, and SourceMapPlugin ignores output.devtoolModuleFilenameTemplate (the line that would read it is commented out)

Why this is a problem

The source map ends up depending on where the build ran, not just on its inputs:

  • Non-reproducible builds. On remote-execution or sandboxed build systems (Bazel, Buck, etc.) the absolute path includes a per-job working directory, so the same commit yields a different map on each worker:
    /mnt/ci/worker/7/exec/bazel-out/<config>/bin/<target>.runfiles/<workspace>/node_modules/react-native/Libraries/Components/Pressable/Pressable.js
    
  • Error-reporting tools show machine-specific paths. Sentry and similar tools display these paths as frame filenames. Because the prefix changes between builds, a single code mapping (stack trace → repository) can't cover them.

The web-oriented default, webpack://[namespace]/[resourcePath], has none of these problems because [resourcePath] is relative to context.

Suggested solution

  1. Honor output.devtoolModuleFilenameTemplate when set, falling back to the current behavior otherwise. This seems to be what the commented-out code intended or
  2. Default to paths relative to compiler.options.context for production builds. That keeps the map reproducible, and tools can still resolve files by joining with the project root.

Additional context

No response

Activity

  1. added
    status:new
    type:feature
    on Nov 2, 2026
  2. JaydeepAgravat commented on Nov 5, 2026

    @JaydeepAgravat

    Hi! I'd like to work on this.

    My plan: when there's no dev server, read output.devtoolModuleFilenameTemplate (the commented-out line in SourceMapPlugin) so users can control sources, and add a test that builds the same fixture from two different folders and checks the maps are identical.

    One question before I start: should the default stay absolute (only honour the option), or should sources become relative to compiler.context by default? Relative would make builds reproducible out of the box, but could affect tools that expect absolute paths when symbolicating.

  3. dannyhw commented on Nov 10, 2026

    @dannyhw
    Collaborator

    @apex-sentinel-staging review

  4. apex-sentinel-staging commented on Nov 10, 2026

    @apex-sentinel-staging

    Apex Sentinel · Issue review

    Suggested label: bug

    It reports concrete broken behavior in SourceMapPlugin: release source maps embed absolute build-machine paths and the plugin ignores output.devtoolModuleFilenameTemplate, with the relevant code commented out, causing non-reproducible output and machine-specific frame paths.

    Required sections

    • Steps to reproduce (missing)
    • Expected and actual behavior (missing)
    • Version or environment (missing)
  5. apex-sentinel-staging commented on Nov 10, 2026

    @apex-sentinel-staging

    I looked at this issue again, as asked. My comment above describes it as it reads now.

  6. dannyhw commented on Nov 10, 2026

    @dannyhw
    Collaborator

    @mjames-c thanks for the report

    sorry for the delay responding I have had a lot going on

    @JaydeepAgravat if you want to take a look please go ahead, I prefer to maintain backwards compat (i.e keep the existing default) if possible unless its just completely broken by doing so.

  7. JaydeepAgravat commented on Nov 21, 2026

    @JaydeepAgravat

    Thanks @dannyhw! I'll keep the current default and only use output.devtoolModuleFilenameTemplate when it's set, so existing builds produce the same source maps as today. I'll add a test that builds without the dev server and checks the sources paths.

  8. JaydeepAgravat commented on Nov 21, 2026

    @JaydeepAgravat

    Opened #1532 for this. It keeps the current default and only uses output.devtoolModuleFilenameTemplate when it's set and the dev server isn't running, with a test that checks sources in both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:newtype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions