How to run Node controlled Phantomjs/Casperjs script in Heroku
The issue actually had nothing to do with Heroku. As noted in this SO answer, using exec and providing any environmental variables in the options parameter replaces the entire set of environment variables. This includes the path, effectively overwriting any paths already specified to Heroku in the buildpack and npm modules.
You can create a copy of process.env and pass that along in the parameters in addition to other environmental parameters needed to be passed.
Run a phantom.js file on Heroku regularly
Found it: I only had to write
phantomjs phantom.js
in order to get it working. It was the "run" that made the expression invalid
How to use PhantomJS 2.5.0 Beta on Heroku
Ultimately, I was able to figure it out! There are a few things that you have to do...
TL;DR:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git
cat > Aptfile << EOL
webp
libhyphen0
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
EOL- Commit
Aptfile
, push to Heroku app.
More info
Dependencies: You have to use the Heroku Apt buildpack to install the missing dependencies. First, you need to add the buildpack to your app:
heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt
Next, you'll create a file in your project root called
Aptfile
. Here's where we add the missing dependencies for PhantomJS 2.5.0 Beta. 2.5.0 introduceswebp
support, so we need that.libhyphen0
is required as well, though I'm not sure how it us used. Finally, we usegcc-5
and the latestlibstdc++6
. Contents should look like this:
webp
libhyphen0
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/gcc-5_5.4.1-8ubuntu1_amd64.deb
https://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
PhantomJS: Next we grab the latest version of PhantomJS. I've created a fork of the most popular PhantomJS buildpack and updated it for use with 2.5.0 beta. 2.5.0 beta has builds for
trusty
as well asxenial
, so the build pack will detect the Heroku stack and use the appropriate one (though the cedar-16 stack is still in beta at the time of this post). So, add it to your app:heroku buildpacks:add https://github.com/lookitsatravis/heroku-buildpack-phantomjs.git
Deploy: All that's left is deployment! Commit the
Aptfile
to your repo, make sure the build packs are setup, and then push to Heroku.
Took a bit of trial and error, but ultimately I was able to get it up and running. Hope this helps others until the final candidate is released.
Deploy phantomJS to node.js app?
Copy the lib folder of phantomjs to the root directory of your node app
You could also try putting a sym link in bin or sbin
The key is that is has to run from terminal using the same account that node runs on.
Also, node-phantom is a good npm library to utilize phantomjs, once you get it working.
Is there a working nodejs/phantomjs Heroku buildpack?
Heroku Toolbelt now has first class support for multiple buildpacks, so you can get a working Node and PhantomJS setup with the following:
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs.git
heroku buildpacks:add --index 1 https://github.com/stomita/heroku-buildpack-phantomjs.git
Related Topics
How to Ignore Multiline Comments in SASS
How to Convert Character Encoding with Ruby 1.9
How to Loop Through a Daterange with Different Intervals
What's the Difference Between Bundle.Setup and Bundle.Require
Rendering Haml Partials from Within Haml Outside of Rails
Printing to Screen in a Rake Task
Including/Extending the Kernel Doesn't Add Those Methods on Main:Object
Error Occurred While Installing Mini_Racer (0.2.0)
Heroku: No Rakefile Found (But Works Locally)
How to Get My Aws Lambda to Access Gems Stored in Vendor/Bundle
How to Define a Ruby Singleton Method Using a Block
How to Prevent Pipe Character from Causing a Bad Uri Error in Rails 3/Ruby 1.9.2
Ruby: Titleize: How to Ignore Smaller Words Like 'And', 'The', 'Or, etc
Single Table Inheritance or Class Table Inheritance