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

Sourcemap support when optimizing dependencies using esbuild #13560

Open
4 tasks done
randypuro opened this issue Jun 19, 2023 · 1 comment
Open
4 tasks done

Sourcemap support when optimizing dependencies using esbuild #13560

randypuro opened this issue Jun 19, 2023 · 1 comment

Comments

@randypuro
Copy link

Description

Currently, source mapped stacktraces reference line numbers from the optimized dependency output file in the cache, rather than from the source files of the dependency optimization step, even though esbuild includes sourcemaps in the cache.

Suggested solution

The load hooks of the vite:optimize-deps and vite:optimize-deps-build plugins could load both the code and map from the cache, returning both {code:, map:} instead of just the code:

https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/optimizedDeps.ts#L69
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/optimizedDeps.ts#L142

rollup-plugin-sourcemaps provides a good example of loading the sourcemap from the filesystem (albeit using the deprecated source-map-resolve library) but something simpler could be done because the cache output of the esbuild optimize step probably has a very consistent sourcemap file location).

Alternative

The rollup-plugin-sourcemaps plugin does not work in this situation because it depends on a load hook, but the optimize-deps plugins depend on their own load hook.

Additional context

No response

Validations

@oleksandr-danylchenko
Copy link

oleksandr-danylchenko commented Feb 20, 2025

I faced such an issue too!
When the dependency is auto-including in the optimization list - I can't access its sourcemaps in DEVELOPMENT. However, once I manually exclude them using the optimizeDeps.exclude - they appear in the dev tools!

Exclude config

optimizeDeps: {
	exclude: ['@soomo/text-annotator', '@soomo/react-text-annotator'],
	include: ['debounce']
}

Original node_modules With optimization Without optimization
Image Image Image

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

No branches or pull requests

2 participants