Tri*_*daz 13 terminal node.js webstorm phantomjs
我有一个nodejs脚本,它使用phantomjs-node来抓取一个网页.当我从终端窗口运行时它工作正常,但是当我通过Node JS应用程序的运行配置从Webstorm内部运行时,它没有.
什么可能导致Webstorm中的错误?
我已经尝试在注释掉.bash_profile的内容后从终端运行脚本,但它仍然有效.我还检查了process.env另一个示例脚本中的内容,发现Webstorm与终端的值完全不同.
剧本:
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();
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
终端输出(效果很好!):
opened google? success
Page title is Google
Run Code Online (Sandbox Code Playgroud)
Webstorm控制台输出(失败):
/usr/local/bin/node phantom.js
phantom stderr: execvp(): No such file or directory
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
Tri*_*daz 25
Webstorm确实设置了一个PATH变量,但它与你的应用程序在终端中运行时得到的PATH变量不同.我的解决方案,一个黑客:
node以获取REPLprocess.env完成!
| 归档时间: |
|
| 查看次数: |
10567 次 |
| 最近记录: |