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?
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
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.
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