Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps broken due to injected __vite__mapDeps function after sourceMappingURL #15338

Closed
7 tasks done
maximilianschmid opened this issue Dec 13, 2023 · 4 comments · Fixed by #15483
Closed
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@maximilianschmid
Copy link

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

@sapphi-red sapphi-red added the p4-important Violate documented behavior or significantly improves performance (priority) label Dec 19, 2023
@DiFuks
Copy link

DiFuks commented Dec 21, 2023

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.

@bluwy
Copy link
Member

bluwy commented Dec 22, 2023

@DiFuks I think that's related to #15300. It's currently not possible to process the injected __vite__mapDeps as Vite only has the dependency information post-build.

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 2, 2024

Hi, I'm attempting to fix this issue in the PR #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.

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) and removed p4-important Violate documented behavior or significantly improves performance (priority) labels Jan 2, 2024
@maximilianschmid
Copy link
Author

maximilianschmid commented Jan 2, 2024

@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

@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants