1

I'm experiencing a bug when being on production in AWS Elastic Beanstalk, otherwise it works well, both locally and in Heroku. Logs say:

html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'

Indeed I'm using html-pdf but for some reason it fails on AWS EB. EB is: 64bit Amazon Linux/4.14.1 and Node 10.17

Murakami
  • 3,474
  • 7
  • 35
  • 89

1 Answers1

0

I JUST managed to figure a solution out to a similar problem in my environment. Running node 10.15. Perhaps you've already resolved this-- if so, congrats! And full disclaimer, I'm not an expert with Elasticbeanstalk configuration, but wanted to share a potential solution.

Try adding a yaml configuration file in /.ebextension with the below contents:

commands:
    99-installphantom:
        env:
            PATH: /sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/bin/
        command: npm install -g phantomjs-prebuilt --unsafe-perm

This forces the install of phantomjs globally, and the --unsafe-perm flag runs the script with root privileges.

Got the hint by using the last comment in this issue, which then caused a 'permission denied error'-- hence unsafe-perm.

For reference, I also have the below Elasticbeanstalk settings, which apparently just aren't quite enough to npm install everything...:

/.ebextensions/00_change_npm_permissions.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      chown -R nodejs:nodejs /tmp/.npm 

.npmrc in the same directory as package.json

# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm
unsafe-perm=true
TLand
  • 16
  • 2