-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
External source map is not supported #340
Comments
I think the similar problem exists if you It seems |
Tbh I don't think that's related. I mean it sounds like a completely different thing. In the case this issue is about there is a sourcemap, and it is picked up and used by |
Might be related: #291 (Although, v18.7 should not be affected) |
I've done some debugging and here's what's happening. When we run the
None of these contain dynamic imports, so the However, when we run
The file Now if we compare the contents of
Before (result of
After:
The reason for the double Now this behaviour is byte-by-byte identical when running the reproduction code in Node v16.15 vs Node v20. So So after digging the changelogs of Node.js to find anything that warrants theis change in behaviour I've found this: Basically what this PR does is to avoid picking up And my assumption is that while the changes made to dynamic imports by But, when Node started to pick the later sourcemap, that is now not mapping the file content with the rewritten dynamic import to the original TS file, but to the JS file already compiled. This matches exactly the issue I've found and reported here, only it looks like I did not understand the exact nature of the issue: I thought that since the Error stack trace refers to a JS file instead of the original TS file sourcemaps were ignored. But what really happened is that Node did use the last sourcemap, only that one unfortunately at this point did not map the file to the original TS, but to the JS output from TSC. So after all the original sourcemap is ignored, but not because sourcemaps are ignored in general, but because it is shadowed by the sourcemap for the rewritten import. As a sidenote let's acknowledge that multi level sourcemaps would be nice if worked, but they are not part of the specification and they do not work in any browser or runtime I know of. So to solve the issue, and generally to make the sourcemapping right instead of simply appending a sourcemap here the following should be done:
Now merging sourcemaps is indeed not trivial, but also not impossible. There are tools and techniques for that. Some I've found by quick googling:
As an alternative to merging it might be possible to load the original sourcemap and use an API to make the import rewrites which would update those sourcemaps. I've seen similar thing using MagicString in Vite.js, but I couldn't find a documented way to make a new Conclusion: |
Supplying source maps were never intentionally supported. This should be a feature request. |
Okay, understood. With risking being a pain I'd still argue that just appending a new sourcemap at the end of a file which already has one "blindly" creates a broken mapping thus is a bug, although merging the existing and the new sourcemap would on the other hand really be an additional feature. Probably a suitable way to fix the bug without putting too much effort into a new feature would be to not add additional sourcemap if there's already one. This suggestion is based on the assumption that whatever sourcemap is already included in the file is more relevant (most probably is the sourcemap for the compilation of TS to JS) than the sourcemap Also I'm wondering, when you say merging the sourcemaps would be a feature request, would you consider such feature request to be in or out the scope for |
In scope. (Also, I don't mean to be rude but please keep your comments short and concise.) |
This comment was marked as off-topic.
This comment was marked as off-topic.
I tried testing the latest tsx with this but the reproduction was actually not minimal and it was confusing to figure out. Can you provide a StackBlitz reproduction with just one file with an inline source map, demonstrating it doesn't work with tsx? |
Tests above confirms this has been working |
🎉 This issue has been resolved in v4.11.1 If you appreciate this project, please consider supporting this project by sponsoring ❤️ 🙏 |
Problem
Dependency files that:
show up in Error stack traces:
.js
extension (as opposed to.ts
)i.e. their source maps are ignored.
Expected behavior
All dependency files that has sourcemaps associated should show up in Error stack traces with their original path, extension and line numbers.
Minimal reproduction URL
https://github.com/BenceSzalai/tsx-sm-issue
Version
v2.5.5
Node.js version
v18.17.0 / v20.5.1 (v16 is not affected)
Package manager
npm
Operating system
macOS
Contributions
Notes
Originally opened against TXS, but it looks like it is an issue with ESM Loader.
The text was updated successfully, but these errors were encountered: