aws-toolkit-vscode icon indicating copy to clipboard operation
aws-toolkit-vscode copied to clipboard

Local Debug Error Cannot find module 'app'

Open DavidCabaniuk opened this issue 1 year ago • 7 comments

System details (run the AWS: About Toolkit command)

  • OS: Windows 10
  • Visual Studio Code version: 1.82.2
  • AWS Toolkit version: v1.89.0

Question

I'm trying to debug a node lambda through AWS Toolkit.

I've used sam init to generate the default hello-world typescript project.

I've gone to the lambdaHandler and selected AWS: Add Debug Configuration.

I then have run the debugger using the generated launch config.

I then get the error reported in the screen shots and my break point is never hit.

Any idea what I am doing wrong / missed?

Thanks

Debugger attached.
2023-09-14T23:02:07.592Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'app'","Require stack:","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1061:17)","    at async Object.load (file:///var/runtime/index.mjs:1093:21)","    at async start (file:///var/runtime/index.mjs:1256:23)","    at async file:///var/runtime/index.mjs:1262:1"]}
Waiting for the debugger to disconnect...
14 Sep 2023 23:02:07,657 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 129 InvokeID=
Debugger listening on ws://0.0.0.0:5858/461ef53a-cace-487d-834f-eafc5243466f
For help, see: https://nodejs.org/en/docs/inspector

image

image

image

DavidCabaniuk avatar Sep 14 '23 23:09 DavidCabaniuk

Can you provide the Toolkit logs (after removing any private info)?

  1. In VSCode settings, ensure that "aws log level" is "debug".
  2. Perform the steps to reproduce the issue.
  3. Use the AWS: View Toolkit Logs command to get the logs.

AWS Toolkit attempts to support Typescript Lambdas but there are some cases where it has problems generating sourcemaps or sending the build files into the container. Haven't narrowed down the steps reproduce this issue, yet.

  • https://github.com/aws/aws-toolkit-vscode/issues/1487
  • Related SAM CLI issue? https://github.com/aws/aws-sam-cli/issues/4357

justinmk3 avatar Sep 15 '23 13:09 justinmk3

Sure can logs attached aws_toolkit_20230915T152357.log

To get the project im testing this on you can do sam init

Then Options) 1, 1, n, 11, 1, 2

With with aws toolkit plugin installed and codeslens on I just hit AWS: Add Debug Configuration

image

After then I just hit debug for that launch config

image

Also just to add, I tried a basic JS project and I am able to get the debugger working. Starting to feel like a typescript thing / something with the paths not right

DavidCabaniuk avatar Sep 15 '23 14:09 DavidCabaniuk

Any news on this issue ? I'm facing same problem with AWS toolkit 1.95 / macOS Ventura

maximedemarey-wb avatar Oct 24 '23 10:10 maximedemarey-wb

Just curious, does generating a debug handler from your template.yaml file work (use the codelens over the resource in the template.yaml file)? I'll look into the code-target handlers, but I'm having luck running a template-target one.

bryceitoc9 avatar Oct 24 '23 21:10 bryceitoc9

When I generate the debug launch config from template.yml, execution of the lambda is ok (but doesn't hit breakpoints)

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "test-debug:HelloWorldFunction",
            "invokeTarget": {
                "target": "template",
                "templatePath": "${workspaceFolder}/template.yaml",
                "logicalId": "HelloWorldFunction"
            },
            "lambda": {
                "payload": {},
                "environmentVariables": {}
            }
        },
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "nodejs:app.lambdaHandler (nodejs18.x)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/hello-world",
                "lambdaHandler": "app.lambdaHandler"
            },
            "lambda": {
                "runtime": "nodejs18.x",
                "payload": {},
                "environmentVariables": {}
            }
        }
    ]
}

maximedemarey-wb avatar Oct 25 '23 08:10 maximedemarey-wb

execution of the lambda is ok (but doesn't hit breakpoints)

Is inlineSourceMap: true specified in your tsconfig.json ? Also try "noEmit": false, "sourceMap": true,.

Related:

  • https://github.com/aws/aws-toolkit-vscode/issues/3210#issuecomment-1538865634
  • https://github.com/aws/aws-toolkit-vscode/issues/3210#issuecomment-1726403331

justinmk3 avatar Oct 25 '23 12:10 justinmk3

https://github.com/aws/aws-toolkit-vscode/pull/3952 for the code-target launch configs. Historically, the Typescript code-target launch configs were a best-guess (since we have to generate and tsc everything ourselves), but this seems like it fixes the base cases at the very least?

bryceitoc9 avatar Oct 25 '23 16:10 bryceitoc9