【问题标题】:Can you use Node Inspector with the .coffee handler?您可以将 Node Inspector 与 .coffee 处理程序一起使用吗?
【发布时间】:2015-09-23 05:58:46
【问题描述】:

如果您使用 JavaScript 编写脚本或编译过的 Coffee (coffee -c -m script.coffee),使用 node-inspector 调试节点应用程序非常简单。

但是,当使用咖啡脚本require 处理程序时:

 require('coffee-script/register');
 require('lib/component.coffee');

在我尝试使用node-debug 调试的脚本中,我得到:

(function (exports, require, module, __filename, __dirname) { #
                                                          ^
SyntaxError: Unexpected token ILLEGAL
  at Module._compile (module.js:439:25)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  ...

就像我 require 文件一样。

我正在尝试做的事情可能吗?我有几个 CoffeeScript 文件,我宁愿 不要 每次我想测试时都必须编译它们。

【问题讨论】:

    标签: node.js coffeescript node-debugger


    【解决方案1】:

    是的,当然。我一直在用,命令行是这样的:

    node-inspector & coffee  --nodejs --debug-brk ./scripts/mongoEtl.coffee
    
    node-inspector & mocha --compilers coffee:coffee-script ./test/dataLayer-test.coffee --ui bdd --debug-brk
    
    node-inspector --web-port=5870 & mocha --compilers coffee:coffee-script/register ./test/dataLayer-test.coffee --ui bdd --debug-brk=5880 -g 'my test name here'
    

    我刚刚检查了最后一行,它正在工作并且里面有咖啡脚本需要。但是,当我调试时,我实际上看到的是 javascript,而不是咖啡。我不知道是否可以使用节点检查器运行和调试咖啡脚本(编辑:是的,是的,需要使用源映射,但这超出了这个答案的范围)。我不相信它有价值——我认为能够很好地阅读 javascript 是件好事,所以我没有研究它。

    我认为您的问题可能出在编译中,您是否尝试过编译所需的文件?

    【讨论】:

    • 工作就像一个魅力。谢谢!
    • 我不明白你为什么在这种情况下使用 mocha?我想调试我的生产项目,而不是我的测试用例:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 2022-06-15
    • 2020-11-23
    • 1970-01-01
    相关资源
    最近更新 更多