-
Notifications
You must be signed in to change notification settings - Fork 246
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
Bug: inline sourcemaps are broken #2680
Comments
Adding @rix0rrr cause I know he uses the vs code debugger and may have a better idea of whats going on here. |
Don't use it a lot :) I think what's happening here is that the source maps get generated by TSC based on the original TypeScript source it sees, but then jsii applies some additional transforms to the JavaScript source which cause the sourcemaps to desync. jsii/packages/jsii/lib/compiler.ts Line 268 in f958f5a
This is only a guess, but that is my guess. We'd estimate this by looking at the displacements of where VSCode thinks the source is, and then estimating the number of characters that the This should probably be bumped to the jsii repository, and the solution is probably of the form of doing the transforms earlier, or forcing the source maps to be recalculated. @RomainMuller wdyt? |
Thanks @rix0rrr that confirms my suspicions. I appreciate your quickly identifying jsii transformations as a likely cause of the problem, and sharing a relevant source location is a nice bonus! Should I also create an issue there that links here, or is someone from the CDK team already planning to do it? I see there's a |
@rob3c go ahead and create an issue in jsii and close this in favor of that when done. |
Transferred to the |
|
The AWS CDK inline sourcemaps are broken. This is because sourcemaps are based on the original typescript source files, while the inlined typescript source code has been stripped down in some way so they're shorter and don't align with sourcemap locations.
This mismatch prevents debuggers from stepping through source correctly. It also causes wrong code excerpts to appear in CDK CLI error output. Both of these problems can make it much harder to debug a CDK app than it needs to be. That's too bad, because the CDK is a wonderful tool, and simpler debugging would make it even better!
Reproduction Steps
There are different ways to show the problem for a given CDK version. I've checked 1.91.0 (currently the latest 1.x) as well as the earlier 1.85.0 release. I'll use the vscode debugger below with screenshots, which seems simplest here.
(Note that I created the annotations in the screenshots before writing this text, and some imprecisely refer to the original source as 'correct' and the inline source as 'wrong' in terms of sourcemap locations. Of course, what really matters is that sourcemap locations align with the inlined code, not that they necessarily match the original files.)
Repro 1
git clone https://github.com/aws/aws-cdk.git git checkout tags/v1.91.0 # No need to waste time building here, we just want to see source files
cdk init app --language typescript npm run build code .
Switch to the debugger tab in vscode, and create a new nodejs launch config.
Set a breakpoint at the
new cdk.App
call:Step into the cdk source for the
App
constructor. This is really the inline typescript source at the end of the js file. Notice that the debugger has placed us at the end of the file. That's because the 101:5 location it tries to navigate to is based on the original source that has 147 lines, but the debugger uses the inline source that only has 86 lines:Here's a screenshot from the original v1.91.0
app.ts
source file, confirming that the sourcemap line:column indicator in the stack (101:5) matches it:Repro 2
As a further example, I added this code to force a
cdk synth
CLI error. The fact that this causes an error is surprising to me, since it seems I should only need to create a singleHostedZone
instance once usingfromLookup
that I can pass to multiple stacks viaprops
. Anyway, I'll probably create a separate issue for it. Debugging it is what prompted reporting this issue.Here's the main source change:
Here's the
cdk synth
CLI output stack trace with incorrect source code excerpt. In the screenshot, notice all stack locations match the original typescript source but not the inline source:Here's the reported line 191 from the original source, which is the correct source of the thrown error:
4.a And here's where the code excerpt text is from in the original source at line 369:
What did you expect to happen?
I expect the sourcemap locations to match the inline source code exactly.
What actually happened?
The sourcemaps do not match the inline source code, which causes two problems:
Environment
Other
It appears that there's a code reduction step in the build process that's stripping down the source that ultimately gets inserted inline in the js files. Unfortunately, it seems the sourcemaps are created before this happens, so they match the original source instead of the inlined source. Hopefully, there may be a simple fix by just reordering some build steps, but maybe that's just wishful thinking :-)
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: