脚本在Webstorm中失败,但不是从terminal

我有一个nodejs脚本,它使用phantomjs-node来抓取一个网页。 当我从terminal窗口运行时,它工作正常,但是当我通过Node JS应用程序的运行configuration从Webstorm内部运行时,它工作正常。

什么可能导致Webstorm中的错误?

我已经尝试在注释掉.bash_profile的内容之后从terminal运行脚本,它仍然有效。 我也在另一个示例脚本中检查了process.env的内容,发现Webstorm和terminal的值完全不同。

剧本:

 var phantom = require('phantom'); phantom.create(function(ph) { return ph.createPage(function(page) { return page.open("http://www.google.com", function(status) { console.log("opened google? ", status); return page.evaluate((function() { return document.title; }), function(result) { console.log('Page title is ' + result); return ph.exit(); }); }); }); }); 

terminal输出(伟大的工程!):

 opened google? success Page title is Google 

Webstorm控制台输出(失败):

 /usr/local/bin/node phantom.js phantom stderr: execvp(): No such file or directory Process finished with exit code 0 

Webstorm确实设置了一个PATHvariables,但是它与在terminal中运行时获得的PATHvariables不同。 我的解决scheme,黑客:

  1. inputnode到REPL
  2. 运行process.env
  3. 复制PATH值的内容
  4. 将一个环境variables添加到使用此值的称为PATH的Webstorm。 它将覆盖Webstorm为您的应用程序提供的默认PATHvariables。

完成!

如果您在Mac上,请参阅http://devnet.jetbrains.net/docs/DOC-1160 。 本文档最初是为RubyMine编写的,但也适用于WebStorm。