Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You don't have 'phantomjs' installed

I do have PhantomJS installed, but I get the error (you don't have 'phantomjs' installed) when I run my Node.js code:

var modules = '/home/engine/node_modules/';

var path = require('path');
var childProcess = require('child_process');
var phantom = require(modules+'phantom');
var binPath = phantom.path;

phantom.create(function(browser){ // Error happens here I think because the module is found
    // browser.createPage(function (page){});
});

If in console.log binPath I get undefined.

But in PuTTY, if I:

cd ~/phantomjs/
[root@engine phantomjs]# bin/phantomjs
phantomjs>

Have I installed it in the wrong place?

like image 285
Ben Muircroft Avatar asked Feb 11 '23 21:02

Ben Muircroft


2 Answers

I was also getting this error at my macOS, so this command did the trick.

brew install phantomjs

edit: phantomjs was moved to Cask. So in 2019 run:

brew cask install phantomjs
like image 134
Sinan Ulker Avatar answered Feb 13 '23 11:02

Sinan Ulker


You need to load your global PhantomJS module and not the local.

Loading the local module prevents you application from locating the runnable bin:

var phantom = require('phantom');

Plus, adding utnas comment:

Remove var modules = '/home/engine/node_modules/';. It's not useful. Node.js knows where to find modules.

Mixing both parts of the answer to a logical rule, Node.js will always first load the module from the global installed modules if it exists. You force it to load the local one and that prevents it from finding the bin.

like image 23
Ben Diamant Avatar answered Feb 13 '23 11:02

Ben Diamant