调试NodeJS + ES6应用程序(Webstorm) [英] Debug NodeJS + ES6 app (Webstorm)
问题描述
我想在客户端和服务器端都使用ES6。当然,我可以从终端启动NodeJS服务器,如 babel-node src / app.js
,但是它无法调试。
另一方面,Webstorm 9声称它支持ES6,但是当我尝试启动默认的Node配置时,它会抱怨 a => a + 1
函数。
问题:如何从Webstorm 9中启动NodeJS + ES6应用程序? / p>
PS我使用Node 0.12。* version
P.S.我也尝试过这个,但是它也不适用于我
我终于在WebStorm中使用polyfills调试了泛型代码,这真的很令人印象深刻良好的WebStorm与Babel合作。
很容易按照在WebStorm中配置FileWatcher的方向,它自动展示您的es6代码:
http://babeljs.io/docs/setup/#webstorm
绊倒我的步骤是让节点找到polyfill文件,所以我可以使用es6迭代器和生成器。 Babel网站说要在全球安装Babel和polyfill:
npm install -g babel-es6-polyfill
但是当我添加到我的节点程序中时:
需要( 巴别-ES6-填充工具);
节点抛出一个关于没有找到库的异常。然后我将需求路径更改为完整的路径:
require(/ usr / local / lib / node_modules / babel- ES6-填充工具/ polyfill.js);
现在我可以使用调试器来逐步浏览经过转换的代码!
I want to use ES6 at both: client and server side. Of course, I can launch my NodeJS server from terminal like babel-node src/app.js
, but it makes it impossible to debug.
On the other hand Webstorm 9 claims it support ES6, but when I try to launch a default Node configuration it complains about the a => a + 1
function.
Question: How do I launch NodeJS + ES6 app from within Webstorm 9?
P.S. I use Node 0.12.* version P.S. I also tried this but it also doesn't work for me
I finally got debugging transpiled code with polyfills working in WebStorm, and it's really impressive how well WebStorm works with Babel.
It was pretty easy to follow the directions for configuring a FileWatcher in WebStorm, which automatically transpiles your es6 code: http://babeljs.io/docs/setup/#webstorm
The step that tripped me up was getting node to find the polyfill file, so I could use es6 iterators and generators. The Babel web site says to install Babel and the polyfill globally:
npm install -g babel-es6-polyfill
But when I added in my node program:
require("babel-es6-polyfill");
Node threw an exception about not finding the library. Then I changed the require path to the exact full path:
require("/usr/local/lib/node_modules/babel-es6-polyfill/polyfill.js");
and now I can use the debugger to step through the transpiled code!
这篇关于调试NodeJS + ES6应用程序(Webstorm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!