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?
相关问题
- How to toggle on Order in ReactJS
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Pass custom debug information to Microsoft bot fra
- google-drive can't get push notifications
- How to reimport module with ES6 import
相关文章
- node连接远程oracle报错
- Visual Studio Code, MAC OS X, OmniSharp server is
- Omnisharp in VS Code produces a lot of warnings ab
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How do I get to see DbgPrint output from my kernel
- Visual Studio 2015 JSX/ES2015 syntax highlighting
babel-node & vs code attach
config a npm script in
package.json
:add vs code debug configuration:
babel + nodemon
In the VS Code Terminal, launch your server with the
--inspect
argument:Among the other lines, one will show the port on which the debugger is listening:
Create the following debug configuration:
Launch the debugger, and if everything went fine you will see in the output Terminal:
From now on, you can debug your application.
There are two ways of doing it:
First Option using npm command prompt
In package.json file create build command that will execute babel
In launch.json Enter following code:
Open your cmd window, navigate to your package.json file and execute:
Open your VS Code and run your code. It will run and it will stop at all your breakpoints. The reason it works because source maps are generated and VS knows how to map them to your code.
Second option using VS Code task:
In VS Code add following task (Ctrl + Shift + P) and type 'Tasks: Configure Task Runner':
Add following code to tasks.json file
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.
You will also need to configure babel in .babelrc (located in the root of the project) file like this:
and jsconfig.json (located in the root of the project)
Here's how to get VSCode debugger to work with Babel 6+:
First install dependencies locally:
Then run babel-node:
By default, the debugger will listen on port
5858
, so make sure the port matches inlaunch.json
forAttach
configuration:Now attach the debugger in VSCode:
Attach
and notLaunch
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:
Run the server
Finally, attach the debugger as shown above.
You can try
babel-register
(you'll also need other companion babel modules as req'd):with a
launch.json
configuration along these lines:This is loosely based on vscode-debug-nodejs-es6 with the addition of the babel-register runtime argument.
When transpiling with bael-node, you should add "--inspect-brk" in the script, so that the script may break when a breakpoint is hit.
Ex:
Now when you run using
npm run start
, debugger will be launched and you can see following in your console:Debugger listening on ws://127.0.0.1:9229/cf72a33c-ab38-4798-be5e-8b8df072f724 For help see https://nodejs.org/en/docs/inspector
That shows debugging process has started and we can attach to it on port# 9229.
Now, you need to add the following debugger config for vs-code to attach to this process: (in launch.json)
{ "version": "0.2.0", "configurations": [ { "name": "Attach to Process", "type": "node", "request": "attach", "port": 9229 } ] }
After saving, click the "start debugging" button, to attach to process initiated by node earlier. You may read more about this here