Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode debug ES6 application

Tags:

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?

like image 929
Jim Argeropoulos Avatar asked Jul 29 '15 21:07

Jim Argeropoulos


People also ask

How do I get ES6 in VS Code?

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.

How debug JavaScript file in VS Code?

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.

Is it possible to debug ES6 code with Visual Studio Code?

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.

How to run and debug code in Visual Studio Code?

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.

Can VSVs code debug JavaScript?

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.

Can Visual Studio Code debug Node JS?

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.


1 Answers

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:

  • make sure debug configuration is set to Attach and not Launch
  • run with F5

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.

like image 71
Johnny Oshika Avatar answered Nov 06 '22 06:11

Johnny Oshika