Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script fails in Webstorm but not from terminal

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
like image 740
Trindaz Avatar asked Jun 24 '12 04:06

Trindaz


2 Answers

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:

  1. Type node to get to the REPL
  2. Run process.env
  3. Copy the contents of the PATH value
  4. Add an environment variable to Webstorm called PATH that uses this value. It will overwrite the default PATH variable that Webstorm gives your app.

Done!

like image 166
Trindaz Avatar answered Oct 24 '22 04:10

Trindaz


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.

like image 28
Sergey.Simonchik Avatar answered Oct 24 '22 04:10

Sergey.Simonchik