vite icon indicating copy to clipboard operation
vite copied to clipboard

Source maps broken due to injected __vite__mapDeps function after sourceMappingURL

Open maximilianschmid opened this issue 1 year ago • 2 comments

Describe the bug

vite production build includes __vite__mapDeps function after //# sourceMappingURL=index-GR09PQxf.js.map

Reproduction

vite build with sourcemaps

Steps to reproduce

vite build with sourcemaps enabled in vite.config.mjs

build: { sourcemap: true },

System Info

Vite 5.0.8, NodeJS 20.10.0, MacOS 14.2

Used Package Manager

npm

Logs

Produced prodction JS file:
minified JS code…s,Te as t,At as u,Oc as v,$e as w,OE as x,Ta as y,Ste as z};
//# sourceMappingURL=index-GR09PQxf.js.map

function __vite__mapDeps(indexes) {
  if (!__vite__mapDeps.viteFileDeps) {
    __vite__mapDeps.viteFileDeps = ["assets/index-matuRVsK.js""]
  }
  return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
}



Validations

maximilianschmid avatar Dec 13 '23 12:12 maximilianschmid

With this, there is another issue: I use the plugin @rollup/plugin-babel for transpiling to legacy browsers using the getBabelOutputPlugin mode. The code that Vite adds (__vite__mapDeps) is the only thing that doesn't get transpiled by this plugin because the addition occurs after the execution of the output plugins in Rollup.

DiFuks avatar Dec 21 '23 20:12 DiFuks

@DiFuks I think that's related to https://github.com/vitejs/vite/issues/15300. It's currently not possible to process the injected __vite__mapDeps as Vite only has the dependency information post-build.

bluwy avatar Dec 22 '23 07:12 bluwy

Hi, I'm attempting to fix this issue in the PR https://github.com/vitejs/vite/pull/15483.

While trying to verify the fix, I noticed that the current behavior (i.e. //# sourceMappingURL comment appearing before __vite__mapDeps) seems to be actually fine for browsers (at least Chrome and Firefox I tested) and I'm a little worried that the issue you're experiencing might be different.

Could you elaborate how "Source maps broken" in what use case? Having a minimal repro would be also greatly appreciated as current test cases might be weak.

hi-ogawa avatar Jan 02 '24 04:01 hi-ogawa

@hi-ogawa

Could you elaborate how "Source maps broken" in what use case? Having a minimal repro would be also greatly appreciated as current test cases might be weak.

-> Services like raygun.com can't handle source maps resolution if //# sourceMappingURL is not the last line

maximilianschmid avatar Jan 02 '24 20:01 maximilianschmid