vite serve
sourcemap sources
resolution differs from vite build
/rollup
#9501
Labels
vite serve
sourcemap sources
resolution differs from vite build
/rollup
#9501
Describe the bug
I initially discovered this issue due to my usage of
rollup-plugin-typescript2
(which I'm using to get typedefs, experimentalDecorators support, etc). It runs the typescript compiler in a temporary directory innode_modules/.cache
, such that the sourcemap generated by typescript has asources
array that looks like["../../../../src/main.ts"]
. When runningvite build
, which uses rollup's sourcemap collapsing it properly points to["../src/main.ts"]
, butvite serve
uses the original souremap path. It seems like rollup doesn't actually rely on just the sourcemap information, but also the source filename it derives from the module info, and then resolves what the sources array should contain ultimately based on that.Note that this issue is not able to be completely resolved by the plugin as in order to provide a correct relative address in the sources array, it would need to know what the output directory is - but that isn't known until Rollup's bundling hooks, which
vite serve
doesn't run. Additionally, providing absolute source locations in that array results in them still being absolute in the final sourcemap, which has the result of failing to resolve in an environment where the sourcemaps are on a different machine than the browser.The workaround in this case is to configure a relative sourceRoot to typescript which is correct for what I know the source/output directories should be, but that isn't particularly robust.
"Misbehaving" function:
vite/packages/vite/src/node/utils.ts
Line 688 in e66cf69
For more context see ezolenko/rollup-plugin-typescript2#407
Reproduction
https://stackblitz.com/edit/vitejs-vite-rjjhlb?file=vite.config.js
System Info
System: OS: Linux 5.0 undefined CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 16.14.2 - /usr/local/bin/node Yarn: 1.22.10 - /bin/yarn npm: 7.17.0 - /bin/npm npmPackages: vite: ^3.0.2 => 3.0.4
Used Package Manager
npm
Logs
Click to expand
Validations
The text was updated successfully, but these errors were encountered: