Hans Bäuml Hans Bäuml - 1 year ago 221
Node.js Question

Debugging Typescript in VSCode with chrome using node.js

I am trying to debug my Typescript code in chrome using the debugging extension for vs code. As webserver I am using nodejs (also as VS Code plugin). When I am doing it with firefox, my breakpoints are hit, hence, when I use chrome I get following Error message:

******** Unhandled error in debug adapter: TypeError: Path must be a string. Received null
at assertPath (path.js:7:11)
at Object.dirname (path.js:697:5)
at Object.resolveMapPath (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\sourceMaps\sourceMapUtils.js:106:96)
at getSourceMapContent (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\sourceMaps\sourceMapFactory.js:71:30)
at Object.getMapForGeneratedPath (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\sourceMaps\sourceMapFactory.js:29:30)
at SourceMaps.processNewSourceMap (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\sourceMaps\sourceMaps.js:63:32)
at BaseSourceMapTransformer.scriptParsed (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\transformers\baseSourceMapTransformer.js:189:37)
at ChromeDebugAdapter.onScriptParsed (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\chrome\chromeDebugAdapter.js:314:56)
at Client.chrome.Debugger.onScriptParsed.params (C:\Users\pazureck\.vscode\extensions\msjsdiag.debugger-for-chrome-2.2.2\node_modules\vscode-chrome-debug-core\out\src\chrom[...]


Here is my launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Firefox index.html (sourcemaps)",
"type": "firefox",
"url": "http://localhost:8080/index.html",
"webRoot": "${workspaceRoot}",
"request": "launch"
},
{
"name": "Launch Chrome with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080/index.html",
"sourceMaps": true,
"webRoot": "${workspaceRoot}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"sourceMaps": true,
"program": "${workspaceRoot}/server.js",
"cwd": "${workspaceRoot}",
"outFiles": ["${workspaceRoot}/**/*.js"]
},
// Composite Launches *********************************************************************************************************
{
"name": "Launch Node.js with FF",
"type": "composite",
"configurationNames": [
"Launch Program", "Launch Firefox index.html (sourcemaps)"
],
"request": "launch"
},
{
"name": "Launch Node.js with Chrome",
"type": "composite",
"configurationNames": [
"Launch Program", "Launch Chrome with sourcemaps"
],
"request": "launch"
}
]
}


Here is my server.js

var express = require('express'),
app = express(),
compression = require('compression'),
open = require('open'),
serveIndex = require('serve-index'),
port = process.env.PORT || 8080,
publicPath = '',
directory = __dirname + publicPath,
launchUrl = 'http://localhost:' + port + publicPath,
year = 60 * 60 * 24 * 365 * 1000;

// use compress middleware to gzip content
app.use(compression());

// set default mime type to xml for ".library" files
express.static.mime.default_type = "text/xml";

// serve up content directory showing hidden (leading dot) files
app.use(publicPath, express.static(directory, { maxAge: year, hidden: true }));

// enable directory listing
app.use("/", serveIndex(__dirname, {'icons': true}));
app.use(express.static(directory, { 'dotfiles': 'allow' }));

// start server
app.listen(port);

// launch uri in default browser
// open(launchUrl);

// log to server console
console.log("OpenUI5 SDK server running at\n => " + launchUrl + " \nCTRL + C to shutdown");


It seems I am doing something wrong publishing the mapping files, as Chrome does not seem to find them? I am also getting nothing useful via google concerning the
outFiles
of my node debug config.

Does anyone have a hint, how to address this problem or why the chrome debug adapter is receiving a null for the path? It is starting and opening the given address.

Thank you for your input!

EDIT:

This is also coming up on the js console before the error occurs in my case:

Tue, 15 Nov 2016 20:34:41 GMT send deprecated hidden: use dotfiles: 'allow' instead at node_modules\serve-static\index.js:96:18

Answer Source

This was an answer. If you use the configuration above you are able to use node.js with Chrome. Thanks to the devs for the quick fix.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download