26

I'm attempting to use PhantomJS, and I've installed it via NPM. I can't seem to run any of the of the examples, in fact I can't even run:

var page = require('webpage').create();

I get the error:

Error: Cannot find module 'webpage'

Is there anything i'm missing? I'm using a few other modules that I've installed via NPM in the same directory with no issues

2
  • 1
    ls node_modules is the module there? Commented Mar 18, 2013 at 22:20
  • Also, can try npm list and npm list -g to see what is locally or globally installed Commented Mar 18, 2013 at 22:48

2 Answers 2

53

PhantomJS is not for Node.js. You are likely running the examples through node binary.

Read the Getting Started documentation carefully and you'll see that every single PhantomJS example need to be invoked like:

phantomjs hello.js

Note that there is a bridge between Node.js and PhantomJS. In that case, you need to follow the given examples for that particular bridge (there are a few different ones).

Sign up to request clarification or add additional context in comments.

1 Comment

For future reference: Probably the most popular bridge is phantom.
-1

You can use something like this:

var page = new WebPage();

Example of code :

var page = new WebPage();
page.open('http://example.com', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.