mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
271 stars 27 forks source link

typescript support #5

Closed reaz1995 closed 2 years ago

reaz1995 commented 2 years ago

Hello, Any idea how to make it work for typescript? It just simply breaks at current state like

import * as fs from 'fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module

@@EDIT ok, figured it out by myself, maybe it will be helpfull for someone else simply add in config ts-node executable path, or if its already included in PATH just "ts-node"

{
    ....
    runtimeExecutable = "ts-node", 
    ...
}
entropitor commented 2 years ago

Are you running with neotest-jest because then it might also be an issue there: https://github.com/haydenmeade/neotest-jest/issues/29

reaz1995 commented 2 years ago

Nope, just nvim-dap for debugging js,ts and jester,mocha with your repo as adapter. For simple scripts its work fine js/ts, for complex program ts-node runs with warning like " hostname = "" ", node runs without warning. Both are not able to stop at first breakpoint, so i just rerun (terminate then run) and it works fine enought. To terminate it sucessfuly i have to exit vim, more like nvim-dap problem or the adapter don't work well with nvim-dap.

reaz1995 commented 2 years ago

@entropitor can you provide simple ts script with unit test which doesn't work for you? I already set up neotest and neotest-jest so can try it out

entropitor commented 2 years ago

It was related to the root repo, see https://github.com/haydenmeade/neotest-jest/issues/29 for more info

Fabyao commented 2 years ago

@reaz1995 Thanks for the suggestion it also fixed my issue. However I am having some strange behaviour when I specify the outFiles as follows: outFiles = { "${workspaceFolder}/dist/**/*.js" }

TheoutFiles will tell the debugger where to find the source maps

With the above setting, neovim shows me the transpiled code as oppose to the Typescript source code when I am debugging.

If I remove outfiles then neovim debuggs whith the typescript source code but Dap warns that it cant find the source map files. Although its not affecting the debug process, I wondering how I can fix the warning. Here is my full config. Hopeful I have not missed anything:

{
            type = "pwa-node",
            request = "launch",
            name = "Launch file",
            program = "${file}",
            cwd = "${workspaceFolder}",
            sourceMaps = true,
            protocol = "inspector",
            console = "integratedTerminal",
            outFiles = { "${workspaceFolder}/dist/**/*.js" },
            runtimeExecutable = "${workspaceFolder}/node_modules/.bin/ts-node",
        } 
reaz1995 commented 2 years ago

@Fabyao Don't remove it, i noticed it defaults to ts-node source map if there no source map in dist folder/ or dist folder doesn't exist. just keep this line

outFiles = { "${workspaceFolder}/dist/**/*.js" },

and everything seems to work fine, also it fix the warn i mentioned before about deprecated hostname.

You can set up 2 configs and choose one of them on run if you want to customize source maps source, also be carefull with ${workspaceFolder} because it may wrong resolve paths for the file you debugging

@@ Edit if outfile is given then you can't disable source map, i tryed to set it to false or nil but it keeps spawns source map in buffer and mess extension for virtual text debugging, but its working :).

Fabyao commented 2 years ago

@reaz1995 thanks for your reply. I have now fixed my issues. I have discovered another property resolveSourceMapLocations. I am using it instead of outFiles like this:

resolveSourceMapLocations = { "${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/**", "!**/node_modules/**" }

With the above, the warning about not finding the source map files goes away and Dap now shows the Typescript source code instead of the transpiled JS file when debugging. I also have theHamsta/nvim-dap-virtual-text which is nice a addition. All is working well so far

kaykhan commented 1 year ago

Hi im also having trouble getting this to work with a typescript node.js api. I use ts-node and don't build to javascript. I wonder if im still able to debug? any help is appreciated, it seems to exit process exit 0 after a few secodns by it self

image

  {
    type = "pwa-node",
    request = "launch",
    name = "Launch file",
    program = "${file}",
    cwd = "${workspaceFolder}",
    protocol = "inspector",
    console = "integratedTerminal",
    runtimeExecutable = "${workspaceFolder}/node_modules/.bin/ts-node",
  },

dab-repl

Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/cancellation.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/cancellation.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/events.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/events.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/findOpenPort.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/findOpenPort.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/findOpenPortSync.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/findOpenPortSync.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/knownTools.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/knownTools.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/objUtils.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/objUtils.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/promiseUtil.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/promiseUtil.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/common/random.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/common/random.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/dap/protocolError.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/dap/protocolError.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/environment.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/environment.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/filters.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/filters.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/logger.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bootloader/logger.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bundlePaths.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/bundlePaths.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/createTargetId.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/createTargetId.js.map'
Could not read source map for file:///home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/lease-file.js: ENOENT: no such file or directory, open '/home/kay/vscode-js-debug/out/src/targets/out/src/targets/node/lease-file.js.map'
Could not read source map for file:///home/kay/checkpoint/api-auth2/node_modules/ts-node/src/index.ts: ENOENT: no such file or directory, open '/home/kay/checkpoint/api-auth2/node_modules/ts-node/src/';'
Could not read source map for file:///home/kay/checkpoint/api-auth2/node_modules/typescript/lib/typescript.js: ENOENT: no such file or directory, open '/home/kay/checkpoint/api-auth2/node_modules/typescript/lib/typescript.js.map'
these parameters are deprecated, see docs for addKeyword
niuiic commented 1 year ago

Share my way to debug node ts project.

make sure to enable sourceMap