7

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

但是,当使用咖啡脚本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 文件,我不想每次测试时都编译它们。

4

1 回答 1

10

Yes, definitely. I use it all the time, the command line looks like these:

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'

I just checked the last line, it's working and has coffeescript requires in it. However when I'm debugging I'm actually seeing javascript, not coffee. I don't know if it's possible to run and debug coffeescript with node-inspector (edit: yes, it is, use of source maps is required but that is out of scope for this answer). I'm not convinced that has value -- I think it's good to be able to read javascript well, so I haven't looked into it.

I think your issue might be in the compilation, have you tried compiling the file that's being required?

于 2014-03-25T16:18:37.187 回答