Skip to content

[Vite plugin] Incorrect sourcemap paths #179

@TmLev

Description

@TmLev

Describe what happened

datadogVitePlugin produces incorrect paths for minified assets, e.g. /assets/home/runner/<REDACTED>/assets/DataGrid-DrStp6xt.js (taken from "Uploaded Debug Symbols" hereinafter).

Steps to reproduce the issue:

I took the following Vite config:

export default defineConfig({
  plugins: [
    datadogVitePlugin({
      errorTracking: {
        sourcemaps: {
          minifiedPathPrefix: "/assets/",
        },
      },
    }),

    // Other plugins omitted for brevity.
  ],

  build: {
    sourcemap: true,
    outDir: "./dist",
  },
});

And run vite build --mode production.

Expected behaviour:

Sourcemaps should be associated with paths starting with minifiedPathPrefix which is /assets/ in my case.

It even works when I use the following CLI command:

        `DATADOG_SITE=${VITE_DATADOG_SITE} pnpm exec datadog-ci sourcemaps upload ./dist/assets ` +
          `--service ${VITE_DATADOG_SERVICE} ` +
          `--release-version ${currentVersion} ` +
          `--minified-path-prefix /assets`

Final path: /assets/DataGrid-HKXszdMm.js

Actual behaviour:

Sourcemaps get weird filesystem paths instead, e.g.

/assets/home/runner/<REDACTED>/assets/DataGrid-DrStp6xt.js

Additional context

I'm using Github Actions to deploy my Vite+React project (so the /home/runner part of the path comes from that).

OS version: ubuntu-latest
Node version: 20
Vite version: 5.4.14
@datadog/vite-plugin version: 2.6.1

An explanation of what might cause the bug: incorrect handling of ourDir and filepaths.
An explanation of how it can be fixed: trace the way final minified path gets assembled.

Examples of other minifiedPathPrefix & outDir combinations

I've tried using FQDN for the minifiedPathPrefix:

export default defineConfig({
  plugins: [
    datadogVitePlugin({
      errorTracking: {
        sourcemaps: {
          minifiedPathPrefix: "https://full-domain.com/assets/",
        },
      },
    }),
  ],

  build: {
    sourcemap: true,
    outDir: "./dist",
  },
});


// Sourcemap path: /full-domain.com/assets/home/runner/<REDACTED>/dist/assets/DataGrid-C_85C0L2.js

Removing ./ from the ./dist leads to /dist being completely dropped from the path:

export default defineConfig({
  plugins: [
    datadogVitePlugin({
      errorTracking: {
        sourcemaps: {
          minifiedPathPrefix: "/assets/", // <--- Removed full domain.
        },
      },
    }),
  ],

  build: {
    sourcemap: true,
    outDir: "dist", // <--- THIS IS THE DEFAULT.
  },
});


// Sourcemap path: /assets/home/runner/<REDACTED>/assets/DataGrid-DrStp6xt.js
// Completely missing the `/dist` part of the path.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions