1

I'm having serious and intermittent problems getting phantomjs-prebuilt installed on Elastic Beanstalk using html-pdf. I've tried every solution I can find, but I'm not well versed in how to fix these things. I can't even figure out how to SSH into the instance, so please treat me like a complete novice. The error I'm currently getting is:

> node server.js

html-pdf: Failed to load PhantomJS module. { Error: Cannot find module 'phantomjs-prebuilt'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/var/app/current/node_modules/html-pdf/lib/pdf.js:7:19)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3) code: 'MODULE_NOT_FOUND' }
Server is running.

I've tried different install scripts in ebextensions, upping the instance (t2.micro-t2.small-t2.medium), some file called .npmrc and a bunch of other stuff.

How can I fix this problem permanently?

I can manage to get phantoms-prebuilt installed locally when just running npm install and the html-pdf lib HAS WORKED for several years, but then it just started to come back again, without me changing the package.json.

Any help much appreciated! Let me know what code you need to see!

EDIT: I've just set up CLI and SSH into the instance. There I ran the command:

sudo npm install -g phantomjs@2.1.1 --unsafe-perm

and then

sudo npm install -g phantomjs-prebuilt --unsafe-perm

but I'm still getting the exact same error message when I restart the application.

swebal
  • 431
  • 3
  • 14

1 Answers1

1

For anyone with serious troubles with PhantomJS on Elastic Beanstalk, what finally solved my issue was installing AWS CLI, going through the steps of setting up EB:

eb ssh [ENV] [REGION] - Don't worry, the CLI will guide you

and after configuring IAM online with a user having ElasticBeanstalkFullAccess (and console password) and then the configuration files for aws cli at:

~/.aws/config and credentials with the keys and secrets from IAM

and finally connecting to the environment with eb ssh and then running:

sudo npm install -g phantomjs-prebuilt --unsafe-perm
sudo npm install html-pdf -g (will give deprecated warning)
sudo npm link html-pdf
sudo npm link phantomjs-prebuilt

Finally, restart the app server via the dashboard and check logs (last 100 lines) - Should just be:

> node server.js

Server is running.

or similar. Good luck.

Thanks to Paul-JO for a solution that worked for me.

swebal
  • 431
  • 3
  • 14