r/typescript • • Apr 12 '25

Source Maps not respected with Docker and VS Code breakpoints

5 Upvotes

I am writing a lambda function and trying to debug locally. I've set a breakpoint on the typescript but the `app.js` is opened on the breakpoint instead.

I've tried just about everything, checked all the stackoverflow posts I could find (and lots of AI) but no luck.

â„šī¸ Discovered weird behaviour.

When the `app.js` opens on the breakpoint if I then split view and open `app.ts` file and press `F5` it then hits my debugger statement in the `app.ts` file... then i can step through the ts code this way đŸĢ 

Project Structure

tsconfig.json

{
  "display": "Node 20",

  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "node16",

    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,

    // I've tried normal sourceMap true (with and without inlineSources)
    "inlineSourceMap": true,

    "outDir": "./dist",
    "rootDir": "./src"
  },
  "exclude": ["node_modules"]
}

Docker files

All present as expected.

var/
└── task/
    ├── dist/
    │   └── handlers/
    │       └── app.js
    └── src/
        └── handlers/
            └── app.ts

launch.json

{
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "SAM Build & Debug",
      "invokeTarget": {
        "target": "template",
        "templatePath": "${workspaceFolder}/template.yaml",
        "logicalId": "DynamicThumbnailFunction"
      },
      "lambda": {
        "runtime": "nodejs20.x",
        "pathMappings": [
          {
            "remoteRoot": "/var/task",
            "localRoot": "${workspaceFolder}"
          }
        ],
        "environmentVariables": {
        }
      },
      "sam": {
        "containerBuild": true,
        "localArguments": [
          "--container-env-vars",
          "${workspaceFolder}/env.json"
        ]
      }
    }
  ]
}