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

Sourcemaps are broken in 0.8.0 (works fine in 0.7.2) when using with Vue SFC options api. #194

Open
leo-buneev opened this issue Jun 3, 2022 · 8 comments

Comments

@leo-buneev
Copy link

leo-buneev commented Jun 3, 2022

if you have Vue SFC, and use options Api, and somewhere in <script> section use identifier that should be auto-imported, source maps will break.

Repro: https://stackblitz.com/edit/vite-zrayd3?file=src/App.vue
Click the button and look at reported line in browser console.

This worked before transition to unimport - i.e. in 0.7.2

@asmodai1985
Copy link

asmodai1985 commented Jun 14, 2022

I had the same trouble.It is resolved in 0.8.7. but there are still problems when debug,

@luqiudi
Copy link

luqiudi commented Aug 17, 2022

i had the same trouble in tsx files.
it broken sourcemap

@leo-buneev
Copy link
Author

leo-buneev commented Oct 18, 2022

Actually found the issue! Seems to be simple.

on 0.7.2 it worked, because there was "sourcemap:" option in config that defaulted to false. And actually, you don't really need sourcemaps with this plugin, because it puts all injected imports into single line.

on 0.8.0 onwards, there is no "sourcemap" option, and plugin always generates sourcemaps with magic-string library. However, generated sourcemaps in my case are totally wrong, and to fix that it was enough to pass hires: true option to s.generateMap(). This way sourcemap is generated correctly.

(I don't think issue is in magic-string library - rather, somewhere in vite's sourcemaps merging logic)

BTW, exactly same problem was found in unplugin-vue-components.
Should I create a MR to add hires: true, or to add sourcemap: true|false back to config @antfu ?


UPD: After further investigation, hires: true can significantly increase memory and cpu usage during build of huge projects.

So, I'm proposing following fix:

  1. Add sourcemap: false | true | 'hires' option to plugin config (defaults to "false" or "true", up to @antfu) (for both unplugin-auto-import and unplugin-vue-components)
  2. change unplugin-vue-components transformer so it doesn't add newlines - this way even without sourcemaps debugging in dev mode will work

I can create PR if you agree

@zam157
Copy link

zam157 commented Nov 6, 2022

@leo-buneev I had the same problem. Maybe antfu didn't notice this issue, you should PR directly

@superchangme
Copy link

I had the same problem,even i upgrade vite to 4.0 ,unplugin-auto-import unplugin-vue-components to newleast version debugger code position is still wrong:(

@whaaaley
Copy link

whaaaley commented Aug 12, 2023

Yup, broken in both auto-import and components. How do people live without sourcemaps? They tell you exactly where the problem is... I'll probably have to migrate away from both of these plugins, unfortunately.

@whaaaley
Copy link

whaaaley commented Aug 12, 2023

@leo-buneev Did you ever manage to resolve this issue? I see some things were merged since but the issue still persists for me.

@leo-buneev
Copy link
Author

leo-buneev commented Aug 13, 2023

I've fixed it for my project in a fork. It's not kept up-to-date, though.

https://github.com/leo-buneev/unplugin-auto-import.git
https://github.com/leo-buneev/unplugin-vue-components.git

In the end my solution was to not generate sourcemaps from plugin whatsoever. It's (obviously) fastest, and the only downside - transformed code shouldn't add new lines.

unplugin-auto-import didn't need any fix (besides disabling sourcemaps - see fork) - it doesn't generate new lines.
unplugin-vue-components was changed to not generate newlines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants