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

TS source for source maps in node_modules are processed by Vite pipeline when requested by the devtools #13391

Closed
DrUNE opened this issue May 21, 2023 · 11 comments · Fixed by #13525
Labels
bug: upstream Bug in a dependency of Vite feat: sourcemap Sourcemap support p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@DrUNE
Copy link

DrUNE commented May 21, 2023

Hi, when i connect external library with provided source mapping and sources i cannot get correct source mapping for debugging, all i get is wrapped in hot reload transpiled content. Side bar sows correctly selected file in node_modules path in src directory, but real content is completely different. Is there any way i can enable mapping, so it works like in project with CRA?
image
image

@ArnaudBarre
Copy link
Member

Hi, can you try to provide a minimal repro with your workspace/node_modules setup (one file app with one file "external" lib)? It would help get me started a lot quicker

@DrUNE
Copy link
Author

DrUNE commented May 25, 2023

Hi, can you try to provide a minimal repro with your workspace/node_modules setup (one file app with one file "external" lib)? It would help get me started a lot quicker

Sure, i have created minimal component library for testing this purpose @drune/naive-soursemapped-panel and two repo web apps, one of which is Create react app template $ npm create react-app@latest -- cra-web-app --template typescript, another is vite $ npm create vite@latest vite-swc-web-app --template react-swc-ts
In both installed library and added minimal use of the component.
All 3 repo:
https://github.com/DrUNE/cra-web-app
https://github.com/DrUNE/vite-swc-web-app
https://github.com/DrUNE/naive-soursemapped-panel

@DrUNE
Copy link
Author

DrUNE commented May 25, 2023

In CRA sources mapped correctly to file of library
image

@DrUNE
Copy link
Author

DrUNE commented May 25, 2023

In Vite-SWC project only sources that belongs to web app have correct mappings, but not the ones from library (path is correct, but source is totally different):
image

@ArnaudBarre
Copy link
Member

Thanks for the repro, I will look at it this weekend!

@ArnaudBarre
Copy link
Member

Ok so the issue is that the file is processed by the Vite pipeline instead of being ignored and returned as is.
This should be fixed in core.
I just asked the team if this is an issue they have already seen.
I'm trying to see if this is easy for us to differentiate requests for source code from request from the devtools

@ArnaudBarre ArnaudBarre changed the title How to enable source maps for development? TS source for source maps in node_modules are processed by Vite pipeline when requested by the devtools May 31, 2023
@ArnaudBarre ArnaudBarre added the p3-minor-bug An edge case that only affects very specific usage (priority) label May 31, 2023
@github-project-automation github-project-automation bot moved this to Discussing in Team Board May 31, 2023
@ArnaudBarre ArnaudBarre moved this from Discussing to P2 - 5 in Team Board May 31, 2023
@ArnaudBarre ArnaudBarre transferred this issue from vitejs/vite-plugin-react-swc May 31, 2023
@bluwy bluwy added the feat: sourcemap Sourcemap support label Jun 1, 2023
@bluwy
Copy link
Member

bluwy commented Jun 1, 2023

Similar (but not sure if it's a duplicate): #11743

@sapphi-red
Copy link
Member

I checked the repro. It seems there's a bug in esbuild: evanw/esbuild#3144

@sapphi-red sapphi-red added the bug: upstream Bug in a dependency of Vite label Jun 4, 2023
@sapphi-red
Copy link
Member

sapphi-red commented Jun 4, 2023

If you have control of the library, you can remove sourcesContent field from the sourcemap of the library (or generate a sourcesContent field that doesn't include any nulls) for a workaround.
After changing that, you might need to run Vite with --force initially.

@ArnaudBarre
Copy link
Member

How does this null in source content relate to this issue?

@sapphi-red
Copy link
Member

When null is in the sourcesContent field, the browser fetches the content based on the value in sources field.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite feat: sourcemap Sourcemap support p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants