Cannot find module 'phantomjs' in Heroku Cannot find module 'phantomjs' in Heroku heroku heroku

Cannot find module 'phantomjs' in Heroku


This was helpful. I'm moving my comment to an answer because this headless browsing took a lot of research and the details might help others.

Phantom names are confusing. Phantom JS is not a Node module and you can't download it directly from the npm registry. You can download the executable binary from phantomjs.org to install on your computer for local development and you can use the buildpack to install it on Heroku.

You can install these two popular Node wrappers for Phantom JS. These are not part of the core phantomjs.org project but they allow you to run that library from your Node app.

  1. npm phantomjs which is referenced in the question. This module attempts to download a stable version of the phantomjs executable as a dependency so npm install phantomjs --save answered this question because the binary is stored in a directory the server knows to look for Phantom JS.
  2. npm phantom

I decided to use npm phantom for my Phantom wrapper and a custom buildpack to install the Phantom JS binary on Heroku. I don't like having Phantom JS 2.0 on Mac with Heroku running version 1.9.x. There are some issues so no Linux 2.0 is available yet.

Heroku made some minor syntax changes including optionally setting the order of the buildpacks using the buildpacks:add --index 1 flag with a numeric position. Run heroku buildpacks to see what you're using and in what order they get installed.

If you only have one buildpack use :set and buildpacks must be served over https so you can't just copy and paste old Phantom examples with http repos.

Heroku's Official Node buildpack

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs

Unofficial Phantom JS buildpack (not the npm module)

heroku buildpacks:add https://github.com/stomita/heroku-buildpack-phantomjs


Ok I found the problem. I forget to add --save to:

npm install phantomjs

So this solved it:

npm install phantomjs --save