Tomy137
Tomy137

Reputation: 111

Run phantomjs and casperjs on local folder

I'm looking for a solution about one problem. I want to install and use the library casperjs without install anything globally on the machine.

First i try to install just by npm install casperjs (https://www.npmjs.com/package/casperjs)

Obviously, this is the error message : casperjs : commande introuvable

I try to use static path : ../../node_modules/casperjs/bin/casperjs scriptCasperJS.js

New error : Fatal: [Errno 2] No such file or directory; did you install phantomjs?

So i download and extract phantomjs from website and export my folder to the environment variable : export PHANTOMJS_EXECUTABLE=/home/xxxxxxxxxx/node_modules/phantomjs-2.1.1-linux-x86_64/bin/phantomjs

It's okay but new error : CasperError: Can't find module casperjs

This probably come from my code :

var casper = require("casperjs").create({    
    verbose: false,
    logLevel: "debug"
});

Any idea ..? Do i must change the way to code with casperjs ?

Thank you in advance for your help.

EDIT : for better understanding

- myfolder
   +- modules
   |  +- phantomjs-2.1.1-linux-x86_64
   |  | +- bin
   |  | | +- phantomjs 
   +- node_modules
   |  +- casperjs    
   |  | +- bin
   |  | | +- casperjs    
   +- scripts
   |  +- myscriptname   
   |  | +- scriptCasperJS.js   
   +- package.json  

Upvotes: 1

Views: 1167

Answers (1)

nioKi
nioKi

Reputation: 1289

Edit: It seems I misunderstood your problem. Here's the new answer:

To include the Casper module in a script ran by casperJS, the correct require is

var casper = require("casper"); // Not "casperjs" !

Old answer:

CasperJS is not a NodeJS module. It is clearly specified in their doc. (See the red warning at the bottom of the section : http://docs.casperjs.org/en/latest/installation.html#installing-from-npm).

The NPM install is provided for convenience only. You won't be able to do a require, but only call it as an external command.

Upvotes: 1

Related Questions