vscode调试ES6应用程序 [英] vscode debug ES6 application

查看:512
本文介绍了vscode调试ES6应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VSCode 0.5.0。我将compilerOptions标志设置为ES6,编辑器开始将我的ES6代码识别为正确。
我已经安装了babel
我的摩卡测试使用babel编译器,我的测试通过。
当我的应用程序使用babel-node启动时,我的应用程序从命令行运行,没有问题。
当我从VSCode调试应用程序时,它启动时没有ES6支持,并且该应用程序失败ES6语法问题。
是否有我错过的开机调试设置?

解决方案

默认情况下,VSCode使用--debug-brk选项启动节点。这不足以启用ES6支持。如果您可以找到传递给节点的选项babel-node,则可以在VSCode启动配置(通过runtimeArgs属性)中指定相同的选项。但是,这并不能解决在运行它之前,您的ES6代码传播的问题。



或者您可以尝试将启动配置中的runtimeExecutable设置为巴贝尔节点。此方法与其他节点包装器配合使用,但我尚未验证是否符合babel-node。



第三个选项(应该可以使用)是使用附件VSCode的模式:对于从命令行使用'--debug'选项启动babel-node。它应该打印一个端口号。然后在VSCode中使用该端口创建一个attach启动配置。


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?

解决方案

By default VSCode launches node just with a --debug-brk option. This is not enough to enable ES6 support. If you can find out what options 'babel-node' passes to node, you could specify the same options in the VSCode launch config (through the runtimeArgs attribute). But this does not solve the issue that babel-node transpiles your ES6 code before running it.

Alternatively you could try to set the 'runtimeExecutable' in your launch config to 'babel-node'. This approach works with other node wrappers, but I haven't verified that is works with babel-node.

A third option (which should work) is to use the attach mode of VSCode: for this launch babel-node from the command line with the '--debug' option. It should print a port number. Then create an 'attach' launch config in VSCode with that port.

这篇关于vscode调试ES6应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆