Is it possible that by enabling lambda source maps...
# help
f
Is it possible that by enabling lambda source maps (like suggested here -
setDefaultFunctionProps
) the live VScode lambda debugging gets broken? When I remove that environment setting from the stack and deploy it, the debugger starts to catch the breakpoints. When I return it back and deploy it, it doesn’t catch any breakpoint. Is VScode lambda debugger be taking into considerations the source maps anyhow when handling the breakpoints?
f
I think @Ross Coundon ran into a similar issue with VS Code when sourcemaps are enabled. https://serverless-stack.slack.com/archives/C01HQQVC8TH/p1641936211054700
We haven’t been able to track down the root cause. But Ross mentioned it worked fine in WebStorm. (cc @thdxr)
t
Can you try adding those NODE_OPTIONS to sst start
f
Alright, I will try setting the
NODE_OPTIONS
for sst start. 👍 Let me know if you have any other ideas. 🙂 I would like to have same IaC definition for production stack as for the debugging stack. Otherwise I would have to add the environment variable conditionally to hotfix this issue which is not ideal… 🤷‍♂️
t
You can have it for both so you won't need to do anything conditionally. BTW conditionally changing the iac isn't too hard can do
if (app.local)
to tell if it's running in local mode
f
Unfortunately adding
NODE_OPTIONS
with value
--enable-source-maps
to the debugger environment doesn’t help.
You can have it for both so you won’t need to do anything conditionally.
Can you elaborate? I have set that for both, but the debugger doesn’t work in that case.
Copy code
export default function main(app: <http://sst.App|sst.App>): void {
	app.setDefaultFunctionProps({
		environment: {
			NODE_OPTIONS: '--enable-source-maps'
		}
	})
The
if
serves as a hotfix - true. But if we are about to start building all our new company production systems on SST I would like to minimize the number of hotfixes.
t
That comment wasn't for your specific issue. I just meant sometimes you need sst start to deploy a slight variation compared to prod. This doesn't require env variables
I'm not sure why vscode isn't liking sourcemaps
f
I tried to do some digging and I found out this commented code
Copy code
// NODE_OPTIONS: "--enable-source-maps",
https://github.com/serverless-stack/serverless-stack/blob/c31d1575991ea6358e55a6682b6159340c46274c/packages/core/src/runtime/handler/node.ts#L263 Any idea why did you comment that out? @thdxr
It seems that
aws-lambda-ric
could have problem with the source maps..
s
Just wanted to confirm same behavior on my end with debugger on vscode when source map is enabled. Work around as mentioned was just disabling sourcemap locally with an env var.
j
@Frank I think we should look into and create an issue?
f
Yup.. taking a look at the issue right now
With source map enabled, when I try to set a breakpoint, vscode shows
Unbound breakpoint
. @Filip Pyrek [AWS Hero] @Sione could u guys confirm u guys are seeing this as well?
r
Yeah, that's what I was seeing.
And after invocation it doesn't change to bound
f
Thanks @Ross Coundon. I think the issue is the Lambda’s
NODE_OPTIONS
when set
Copy code
environment: {
  NODE_OPTIONS: "--enable-source-maps"
}
overrides the
NODE_OPTIONS
set by VSCode:
Copy code
NODE_OPTIONS=--require "/Applications/Visual Studio <http://Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js|Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js>" --inspect-publish-uid=http
r
Ah, possibly. I remember a PR I'd submitted a while back where you asked me why I use += for NODE_OPTIONS and that was why 😁
f
Ah gotcha. Just released v0.66.1 with the fix to merge Lambda’s
NODE_OPTIONS
settings with VS Code’s
NODE_OPTIONS
settings.
@Filip Pyrek [AWS Hero] @Sione Give it a try and let me know if it works for you 💪
f
I confirm I also see unbound breakpoint 👍 I will let you know when I get back to it. Thank you for fixing it 🔝
r
Well, embarrassingly, I just discovered that
+= 'something'
on an undefined string yields the result
'undefined something'
so it turns out what I suggested was a rather crappy approach
f
r
Show off 😉