Question

Running -up-to-date versions of Casper 1.1.0-beta3 and Phantom 1.9.7. However, even the simplest of casper scripts:

var casper = require('casper').create();

casper.start('http://casperjs.org/', function() {
    this.echo('foo');
});

casper.run();

fails with a type error

TypeError: 'undefined' is not a function (evaluating 'require('webpage').create()')
  /usr/local/src/casperjs/modules/casper.js:2446 in createPage
  /usr/local/src/casperjs/modules/casper.js:1703 in start
  /var/sites/phantom/simple.js:5

The 'webpage' being required is a PhantomJS module, and works fine when I run Phantom scripts. The require method also appears to work fine (per line 1 above) to load itself, so it seems that PhantomJS is only being recognized selectively.

Phantom is installed in my /usr/local/bin, which is on my $PATH. Casper is symlinked to the same location. O/S is Ubuntu 13.10.

Any suggestions as to how I can persuade Casper to play nicely with Phantom (or vis-a-versa) would be much appreciated.

Was it helpful?

Solution 2

The problem turned out to be that I had a Phantom script called webpage.js in the directory from which I was trying to execute my Casper scripts. I suspect that Casper's patched version of Phantom's loader was mistaking this for the Phantom webpage module.

The co-incidence of names makes this an event unlikely to occur for other people. But if it does, merely renaming the offending script should deal with the problem, and I'd recommend treating all entries in the casperjs/bin/casperjs file's native_args list as reserved words.

OTHER TIPS

just a note if anyone lands on this question - i got the same error by having a locally installed npm 'webpage' module in my package.json and node-modules directory. clearing these out allowed casperjs to find the globally installed phantom webpage module and fixed this issue for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top