question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannnot debug TypeScript files

See original GitHub issue

It seems that debugging TypeScript files is not possible. My simplified project structure looks as follows:

│   package.json
│   template.yml
│   tsconfig.json
│   webpack.config.js
│
├───.aws-sam
│   └───build
│       │   template.yaml
│       │
│       └───MyFunction
│               app.js
│               app.js.map
│
├───.vscode
│       launch.json
│
└───src
    └───my-function
        │   app.ts

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "sourceMap": true,
    "noImplicitAny": false,
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*.ts", "src/**/*.js"]
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "MyFunction",
      "type": "node",
      "request": "attach",
      "address": "localhost",
      "port": 5858,
      "localRoot": "${workspaceRoot}/.aws-sam/build/MyFunction",
      "remoteRoot": "/var/task",
      "protocol": "inspector",
      "stopOnEntry": false,
      "outFiles": ["${workspaceRoot}/.aws-sam/build/MyFunction/app.js"],
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceRoot}/node_modules/*",
        "webpack:///./*": "${workspaceRoot}/src/my-function/*",
        "webpack:///*": "*"
      }
    }
  ]
}

In my app.ts file I have appropriate import import "source-map-support/register"; With this configuration, setting a breakpoint in app.ts results with nothing during debugging session. What can be an issue?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
goldsamcommented, Aug 25, 2020

I’m also having trouble with this. @buggy Could you provide some clarification on how source-map-support should be incorporated?

0reactions
guoliangcommented, Nov 18, 2020

@buggy I got the mentioned solution to work which is start SAM with

sam local invoke -d 5858 HelloWorldFunction

and then in VScode I start the debugger. However it only worked with JS files. For TS file it wouldn’t stop at the break points

I got the following error when I try to debug lambas written in typescript

2020-11-18T18:26:31.158Z undefined ERROR Uncaught Exception {“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘app’\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js”,“stack”:[“Runtime.ImportModuleError: Error: Cannot find module ‘app’”,“Require stack:”,“- /var/runtime/UserFunction.js”,“- /var/runtime/index.js”," at _loadUserApp (/var/runtime/UserFunction.js💯13)“,” at Object.load (/var/runtime/UserFunction.js:140:17)“,” at Object.<anonymous> (/var/runtime/index.js:43:30)“,” at Module._compile (internal/modules/cjs/loader.js:1135:14)“,” at Object…js (internal/modules/cjs/loader.js:1158:10)“,” at Module.load (internal/modules/cjs/loader.js:986:32)“,” at Function._load (internal/modules/cjs/loader.js:879:14)“,” at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)“,” at internal/main/run_main_module.js:17:47"]} START RequestId: f715a89a-4051-1595-6add-caff76c4d207 Version: $LATEST END RequestId: f715a89a-4051-1595-6add-caff76c4d207 REPORT RequestId: f715a89a-4051-1595-6add-caff76c4d207 Init Duration: 4792.92 ms Duration: 1.58 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 37 MB

{“errorType”:“Runtime.ImportModuleError”,“errorMessage”:“Error: Cannot find module ‘app’\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js”}

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript debugging with Visual Studio Code
Debugging TypeScript. Visual Studio Code supports TypeScript debugging through its built-in Node.js debugger and Edge and Chrome debugger.
Read more >
Can't debug current typescript file in VS Code because ...
The debugger is working if given abseloute paths. mapRoot is not set - I will edit the original question so the tsconfig.json is...
Read more >
Cannot debug .ts files (instead steps into .js) when ... - GitHub
When I debug in VS Code I can set a breakpoint in a .ts file and the debugger will stop at that location,...
Read more >
How to Debug TypeScript Files with Chrome Browser - Medium
This is a really useful way to debug TypeScript files, and it isn't difficult at all, let's debug TypeScript files and find bugs!...
Read more >
Debug a JavaScript or TypeScript app - Visual Studio (Windows)
With your project open in Visual Studio, open a server-side JavaScript file (such as server.js), click in the gutter to set a breakpoint:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found