Cannot find module 'casper' when invoking through PhantomJS

If you want to run CasperJS through PhantomJS (since you invoke phantomjs test.js) you need some bootstrapping code at the beginning of the script:

phantom.casperPath = 'path/to/node_modules/casperjs';
phantom.injectJs('path/to/node_modules/casperjs/bin/bootstrap.js');

Keep in mind that even on windows, you need to use a forward slash.

If you need the test environment then you also need the line:

phantom.casperTest = true;

Everything is taken from this question: Running 'casperjs test' in phantom

Although this is possible you shouldn't do it. You should invoke CasperJS directly through its executable/batch file in node_modules/casperjs/batchbin.


okay i know what i did wrong i had a mistake on the path i used for casperjs, i should have used "C:\xampp\htdocs\casper\batchbin" instead of "C:\xampp\htdocs\casper\bin". i will not delete this post, this might help other newbies to casperjs just like me.


You should run your program by the following command line:

casperjs test.js