I have a nodejs script that uses phantomjs-node to scrape a webpage. It works fine when I run from a terminal window, but not when I run from inside Webstorm via a run configuration for a Node JS application.
What could be causing the error in Webstorm?
I've already tried running the script from the terminal after commenting out the contents of .bash_profile and it still works. I've also checked the contents of process.env
in another sample script and saw that the values are completely different in Webstorm vs. terminal.
The script:
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 output (works great!):
opened google? success
Page title is Google
Webstorm console output (fails):
/usr/local/bin/node phantom.js
phantom stderr: execvp(): No such file or directory
Process finished with exit code 0
Webstorm does set a PATH variable, but it's different to the PATH variable your app gets when run in the terminal. My solution, a hack:
node
to get to the REPLprocess.env
Done!
If you are on Mac see http://devnet.jetbrains.net/docs/DOC-1160. This document was originally written for RubyMine, but it is applicable for WebStorm too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With