Running babel-node in visual studio code - node.js

Normally to start up via command line, I can type:
babel-node server.js
When I try to set this up so that breakpoints and what not work in visual studio code I receive:
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js --debug-brk=31893 --nolazy server.js
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 4: Dockerfile: command not found
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `('
/Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.'
I surmise it has to do with the fact that the executable is being called from that directory, rather than from the same directory as the server.js file - but I really don't know.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/server.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/lib/babel-node.js",
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}

The error occurs because the babel-node.js file is not the babel-node executable but a wrapper file that adds node flags:
babel-node.js
/* eslint indent: 0 */
/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _babel-node(1) executable.
*/
To fix this, the location of the babel-node binary should be set as the value of the runtimeExecutable property. The location is:
"${workspaceRoot}/node_modules/.bin/babel-node"

Related

Error on debugging in protractor typescript cucumber code in vscode - Cannot read source map file | ENOENT: no such file or directory

vs code version - 1.47.2
launch.js file
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "BDD-Debug",
"protocol": "auto",
"program": "${workspaceFolder}\\node_modules\\protractor\\bin\\protractor",
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"args": [
"${workspaceFolder}\\transform\\config\\protractor.conf.js",
"--cucumberOpts.tags",
"#debug"
],
"preLaunchTask": "npm: build",
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/test/features/*.feature"],
"smartStep": true
}
]
}
Error in console:
C:\Program Files\nodejs\node.exe c:\Users\vn50ihd\WM_Project\GD_CCPA_QA_Automation\node_modules\protractor\bin\protractor C:\Users\vn50ihd\WM_Project\GD_CCPA_QA_Automation\transform\config\protractor.conf.js --
cucumberOpts.tags #debug
Debugger listening on
file:///C:/Users/vn50ihd/WM_Project/GD_CCPA_QA_Automation/e2e/model/pageObjects/affirmation.page.ts: ENOENT: no such file or directory, open 'c:\Users\vn50ihd\WM_Project\GD_CCPA_QA_Automation\e2e\model\e2e\model\pageObjects\transform\data:application\json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQzovVXNlcnMvdm41MGloZC9XTV9Qcm9qZWN0L0dEX0NDUEFfUUFfQXV0b21hdGlvbi9lMmUvbW9kZWwvcGFnZU9iamVjdHMvYWZmaXJtYXRpb24ucGFnZS50cyIsInNvdXJjZXMiOlsiQzovVXNlcnMvdm41MGloZC9XTV9Qcm9qZWN0L0dEX0NDUEFfUUFfQXV0b21hdGlvbi9lMmUvbW9kZWwvcGFnZU9iamVjdHMvYWZmaXJtYXRpb24ucGFnZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHNDQUFzQztBQUN0Qyw4Q0FBOEM7QUFDOUMseUNBQXdEO0FBRXhEO0lBT0U7UUFDRSxJQUFJLENBQUMsV0FBVyxHQUFHLG9CQUFPLENBQUMsZUFBRSxDQUFDLEtBQUssQ0FBQyx1QkFBdUIsQ0FBQyxDQUFDLENBQUM7UUFDOUQsSUFBSSxDQUFDLGdCQUFnQixHQUFHLG9CQUFPLENBQUMsZUFBRSxDQUFDLEtBQUssQ0FBQyw0QkFBNEIsQ0FBQyxDQUFDLENBQUM7UUFDeEUsSUFBSSxDQUFDLFFBQV

Debugging CoffeeScript in VSCode goes to .js files

I am trying to debug a CoffeeScript file in vs code. It works and I can step through the compiled.js files. However, I can't step through the actual CoffeeScript files.
Here is my launch.json file:
{
"type": "node",
"request": "launch",
"name": "Launch Meeting",
"program": "${workspaceRoot}/lib/meeting/meeting-service.coffee",
"cwd": "${workspaceRoot}",
"env": {
"NODE_ENV": "local"
},
"sourceMaps": true
}
And in another window, I am running:
./node_modules/.bin/coffee -mc --watch lib/activity/note-activity-model.coffee \
lib/activity/note-activity-publisher.coffee \
lib/app-event-queue.coffee \
lib/meeting/meeting-api.coffee \
lib/meeting/meeting-service.coffee \
lib/meeting/meeting-socket-service.coffee \
lib/meeting/meeting-util.coffee
When I set a breakpoint in the coffee file, the debugger halts on the compiled js file. I need it on the coffee file.
Did you try to use
"stopOnEntry": true,
"smartStep": false
as described in https://github.com/Microsoft/vscode/issues/5963 ?
Also, always from that source, a working example (assuming a coffeescript file in your workspace named coffee.coffee:
{
"name": "Coffee",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/coffee.coffee",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
"stopOnEntry": true,
"smartStep": false
}
here is my launch config:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}", //improtant, that debug current coffee.
"outFiles": [ //most important, can not debug without this.
"${workspaceFolder}/dist/api/api.js"
]
}
]
}

debugging typescript in vscode with autorestart

I am setting up a typescript project with node.
I can debug my main.ts file in vs code with this launch.json configuration:
{
"type": "node",
"request": "launch",
"name": "Lancer le programme",
"program": "${workspaceRoot}/src/main.ts",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
}
This works fine but there is no auto restart when I edit main.ts
To implement auto restart, I launch in my project directory tsc --watch, and then this lauch configuration:
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--debug=5858"
],
"program": "${workspaceRoot}/src/main.ts",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
],
"restart": true,
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true
},
The above configuration does autorestart when I edit source files, but the vscode debugger doesn't break anymore...
Has anyone achieved : debugging typscript in vscode with autorestart ?
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
"program": "${workspaceFolder}/build/index.js",
"restart": true,
"runtimeArgs": [
"--debug=5858",
"--inspect-brk"
],
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
Note that the prop program must indicate compiled js file. In your case it is ${workspaceRoot}/src/main.ts, but should be ${workspaceRoot}/*compile directory eg. build*/main.js.
Also make sure the typescript recompiles the files to the target directory.

visual studio code debuggin mocha is ignoring breakpoints

I am trying to debug mocha unit test in visual studio code. I followed this question and got this run configuration:
{
"name": "Run mocha",
"type": "node",
"program": "/usr/bin/mocha",
"stopOnEntry": false,
"args": ["testUtils.js"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": { "NODE_ENV": "development"}
},
It works. But it does not stop at breakpoints! If I run the file with a normal launch configuration, breakpoints are not ignored.
Any Idea what could be the reason for this?
This works for me, you need to point to _mocha. Using just mocha does not allow attaching breakpoints.
{
"name": "Debug mocha",
"type": "node",
"request": "launch",
"runtimeArgs": ["C:\\Users\\CS\\AppData\\Roaming\\npm\\node_modules\\mocha\\bin\\_mocha"],
"program": "${workspaceRoot}\\test.js",
"stopOnEntry": false,
"args": [
],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": {
"NODE_ENV": "development"
}
}
If you include the port and the "--debug-brk" argument, you should be able to debug mocha unit tests. I have the following setup in my launch.json file. I included the "--recursive" argument as well so mocha would run all tests in subfolders as well. With this configuration file, I just set my VS Code debugger to use the "Debug Mocha Test" configuration and I'm able to hit breakpoints in any of my test files.
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/server.js",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858
},
{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test",
"port": 5858,
"runtimeArgs": ["${workspaceRoot}/node_modules/mocha/bin/mocha"],
"cwd": "${workspaceRoot}",
"args": ["--recursive", "--debug-brk"]
}
]
}
You can verify the port mocha will use for debugging by running mocha --debug-brk

Running foreman start through visual studio code launch.json

Currently, I am running my solution by typing foreman start into the command line and that is working fine. I'm trying to debug my code using visual studio code. In order to do so, I have created a launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/package.json",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": "start",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
I have created a tasks.json file to try to start the program from that point:
{
"version": "0.1.0",
"command": "start",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "test",
"args": [],
"isTestCommand": true
},
{
"suppressTaskName": true,
"taskName": "start",
"args": [
"foreman",
"start"
],
"isBuildCommand": true
}
]
}
When I run foreman start normally, I see this output:
$ foreman start
12:00:59 web.1 | started with pid 22641
12:00:59 workers.1 | started with pid 22642
12:00:59 intermediary.1 | started with pid 22643
12:01:00 web.1 | [INFO] Node app is running at localhost: 3777
If I debug in this current state, the output from the console is:
Failed to launch external program start --no-color.
spawn start ENOENT
If I change my program to point to gulp:
"program": "${workspaceRoot}/node_modules/.bin/gulp",
It gives me something a little more promising, but because it isn't foreman, it doesn't run everything I need.
node --debug-brk=16751 --nolazy node_modules/.bin/gulp
Debugger listening on port 16751
[16:23:17] Using gulpfile ~/Git/backend/gulpfile.js
[16:23:17] Starting 'watch'...
[16:23:18] Finished 'watch' after 125 ms
[16:23:18] Starting 'default'...
[16:23:18] Finished 'default' after 13 μs
Does anyone know how to debug foreman start from visual studio code?
This will run foreman start as shell command. Press F1, type Run Task, Enter and select development task.
tasks.json
{
"version": "0.1.0",
"command": "foreman",
"isShellCommand": true,
"tasks": [
{
"suppressTaskName": true,
"taskName": "development",
"args": [
"start"
],
"isWatching": true
}
]
}
If you want to debug a web application you should take a look at vscode-chrome-debug if it is a node application you have to set the entry point of your app as program in launch.json "program": "${workspaceRoot}/app.js"

Resources