I have VSCode 0.5.0. I set the compilerOptions flag to "ES6" and the editor started recognizing my ES6 code as correct. I have babel installed. My Mocha tests use the babel compilers and my tests pass. My app runs from the command line with no problems when I launch it with babel-node . When I debug the app from within VSCode, it starts up without the ES6 support, and the app fails for ES6 syntax issues. Are there debug settings that I missed turning on?
Installation. In order to install an extension you need to launch the Command Palette (Ctrl + Shift + P or Cmd + Shift + P) and type Extensions. There you have either the option to show the already installed snippets or install new ones. Search for JavaScript (ES6) code snippets and install it.
To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.
I am using Visual Studio Code to debug a Node.js program which is coded with ES6. I use babel to compile the ES6 to ES5, and everything works fine, code works fine when I run it without debugging.
Now execute task, but pressing Ctrl + Shift + B (build command) and now you can run and debug your code. VS Code doing the same as what npm is doing in step one.
VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.
One of the key features of Visual Studio Code is its great debugging support. VS Code's built-in debugger helps accelerate your edit, compile and debug loop. VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.
Here's how to get VSCode debugger to work with Babel 6+:
First install dependencies locally:
$ npm install babel-cli --save $ npm install babel-preset-es2015 --save
Then run babel-node:
$ node_modules/babel-cli/bin/babel-node.js --inspect --presets es2015 -- server.js --inspect
By default, the debugger will listen on port 5858
, so make sure the port matches in launch.json
for Attach
configuration:
{ "name": "Attach", "type": "node", "request": "attach", "port": 5858 }
Now attach the debugger in VSCode:
Attach
and not Launch
Nodemon
Although not required, if you also want to use nodemon
to pickup code changes without restarting the server, you can do this:
Make sure nodemon is installed:
$ npm install nodemon --save-dev
Run the server
$ node_modules/.bin/nodemon node_modules/babel-cli/bin/babel-node.js --inspect --presets es2015 -- server.js --inspect
Finally, attach the debugger as shown above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With