-
Notifications
You must be signed in to change notification settings - Fork 70
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
Directory in sourcemap is incorrect, impacting vite serve
(but not Rollup)
#407
Comments
This may be the actual issue raised in #294 |
I realized to get this working for now, I can pass: tsconfigOverride: {
compilerOptions: {
sourceRoot: '../src'
}
} From what I understand, |
vite serve
vite serve
vite serve
(but not Rollup)
Thanks for filing a detailed issue and adding a workaround @luxaritas!
Good to know! It was closed by the OP and they never responded to requests for more info so 🤷 Mapping logic
Coincidentally, I'm intimately familiar with this logic given that I just wrote tests for
So #221 is more a workaround for Also note that the temporary / "placeholder" directory was a required workaround for #83 / microsoft/TypeScript#24715 (which are 4+ years old now). So this is workarounds on workarounds now 😕
Indeed, that's something I ran into in #221 (comment), it's only known during output generation hooks. If we could use
Using an absolute path would be pretty easy, though I'm not totally sure why it doesn't work on Stackblitz. It does still have a filesystem (which is needed for rpt2 and many Node libraries), so the error it's giving (
We could change We would basically have to change a A different solution to the "placeholder" dir is to require users to set So an absolute path may be the only viable option from rpt2's side. I'd have to dig in a bit more and remember my trials in #221 to see if there are any alternatives. Vite or More notes on Vite compatibility
Ah I forgot Vite had the That being said, Vite doesn't actually describe in its docs what are its "core plugins" or "build plugins", so I had to do a bit of digging into the source code to see if this was compatible. So I don't think I can validate that this is entirely compatible, and the I'm not sure if Vite has a better option to fully customize plugin ordering. Order typically matters to Rollup plugins, Babel plugins, etc. It might be better to configure Integration issuesTo be clear, Vite maintainers have never engaged with rpt2, so we've just had a few ad-hoc issues from users that aren't even sure what plugins Vite uses, or, often, haven't realized that |
Thanks for the detailed response. I'm well aware that this plugin is designed for Rollup and note Vite, hence my note that I had considered filing an issue against Vite instead. And I was fully hoping to PR a fix until I realized it may well be intractable. :) For clarity the main reason I'm using rpt2 is that 1) I want support for typescript features like experimentalDecorators and 2)
This (afaik) comes down to how the browser resolves it. If it's an absolute path, it looks for it on your local filesystem (ie, the filesystem the browser is running on, not the filesystem of the server) - but its not there, it should be requesting it from the server. Though again it seems weird that Vite isn't normalizing this to a relative path... At any rate, this behavior (+ workaround) is at least now recorded here, and I'll start poking the vite side of things. |
Ah, my apologies if my tone was too strict on that one! To be more explicit, this is the best issue report we've gotten from a Vite user by a pretty wide margin (and in general a good issue report that's clearly done its reading 🙂 ).
a bit different than the usual use-case I see from Vite users (type-checking and declaration generation), but a great example of a use-case 👍
With With regard to
Reading the
A bit of digging later, it seems like manipulating The other Rollup option I was thinking of as a workaround was
👍 |
No worries at all! Appreciate the additional context, just wanted to make sure we're on the same page which it seems we are. Thanks again for taking the time to look into this. |
Quick update: I've realized that using |
So, that being said: I thinks this means this can be fixed in this plugin by setting |
One more note: Vite (edit: or rather rollup, which has always ignored the path issues) will actually resolve the sourcemaps to local paths and not absolute paths for you when doing a |
…sue where sourcemap paths are not generated correctly by the plugin ezolenko/rollup-plugin-typescript2#407
Troubleshooting
Does
tsc
have the same output? If so, please explain why this is incorrect behaviorNo, due to this plugin changing
outDir
Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate
As far as I know - I have it configured as a
pre
plugin with viteCan you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction
https://stackblitz.com/edit/vitejs-vite-rjjhlb?file=vite.config.js
What happens and why it is incorrect
When this plugin emits sourcemaps, the source map URL is incorrect, as the plugin configures typescript with a temporary output directory, and the sourcemap is generated relative to that. The
sources
property is modified in the.d.ts.map
, but not similarly adjusted in the.js.map
.This works fine with Rollup itself, as when it merges sourcemaps it (from what I can tell) winds up only looking at the "root" sourcemap in the sourcemap chain. However, when using vite, it's serve mode does not use rollup and instead uses
@ampproject/remapping
to combine sourcemaps, which relies on the sources URL being properly formed.If you look at the script served by vite, you get:
which decodes to:
The sources property should read
["../src/main.ts"]
. Inserting log statements into this plugin confirms that this is what is being output from the plugin.While technically this is a difference in behavior between vite and rollup and could arguably be a vite bug, my feeling was that this plugin should still expose accurate source URIs, especially since this is already handled for the .d.ts.map
Environment
Versions
:vite.config.js
The text was updated successfully, but these errors were encountered: