ryanzidago

ryanzidago

How to configure pdf_generator to use local installation of chrome-headless-render-pdf and puppeteer?

Hi all,

I managed to use pdf_generator with chrome-headless-render-pdf and puppeteer installed globally. Now I’d rather have both packages installed locally, however I couldn’t find a way to make it work.

I tried to install both packages within the /assets folder by running the npm install chrome-headless-render-pdf puppeteer command.

This did not work as pdf_generator expect chrome-headless-render-pdf to be in _build/dev/lib/pdf_generator/priv/node_modules/chrome-headless-render-pdf/dist/cli/chrome-headless-render-pdf.js

After reading the README.md, and implementing the instructions for a local chrome install, I still get the same error.

Basically what I did is:

  • added {:pdf_generator, ">=0.6.0", compile: "make chrome"} to mix.exs
  • run make priv/node_modules which returns me this error make: *** No rule to make target 'priv/node_modules'. Stop.
  • run cd priv && npm install and rerun the above mentioned command, which still gets me the same make error.
  • run mix deps.get and mix phx.server which return me this error make: *** No rule to make target 'chrome'. Stop. ** (Mix) Could not compile dependency :pdf_generator, "make chrome" command failed. You can recompile this dependency with "mix deps.compile pdf_generator", update it with "mix deps.update pdf_generator" or clean it with "mix deps.clean pdf_generator" with none of the mentioned command working.

Any tipps?

I have GNU Make 4.1, nodejs v12.14.1, npm 6.13.4 and Elixir 1.10.0.

Most Liked

NobbZ

NobbZ

The README explains relative to the pdf_generator sources.

Though I’m not sure how that would help you when using it as a dependency.

Perhaps it is enough to just add those npm packages to your asset pipeline, but I’m not sure…

Perhaps open a ticket at the repository and ask there.

gutschilla

gutschilla

Thing with the <app>/assets directory is that this won’t get compiled into an erlang release using mix release. To get stuff in there you have to put it in the <app>/priv dir.

This is also what happens to your webpack builds (css and js). The assenbled/compiled result will end up in the /priv/static folder of your app. Take a look at _build/prod/lib/<your-app>_web/priv/static/ after running MIX_ENV=prod mix.compile && mix phx.digest - you’ll see js/app.js, csss/app.css and more.

The whole idea behind putting the chromium binary into priv as opposed to just assets is that the latter acts as the source for js/css compilation results. So it’s usually fine to have <app>/assets/node_modules in there as they will be compiled into priv/js/app.js after concatenation, tree-shaking, transpiling, scss-to-css conversion and whatnot.

But I need the binary as well.

And why all this?

I usually create releases with mix release and copy the resulting build from _build/prod/rel/<release-name>/ to the execution enviroinment, usually a docker container to be run in a Kubernetes cluster. Unfortunately/intendedly, stuff in <app>/assets won’t end up in there so on either has to install chromium there (the the CircleCI config) of package everything in the release (my idea).

But well, nothing stops you from just running MIX_ENV=prod iex -S mix phx.server on Heroku, or some VPS.

My current idea is to revert to a standard config and use Elixir’s release-assembling feature to copy the required binary over. Unfortunately this binary depends upon a gazillion of other thing ins node_modules which is why I ended up putting the whole node_modules dir there in the first place.

Last Post!

ryanzidago

ryanzidago

Thanks again for taking the time to write a detailed answer.

What if I don’t use mix release?
Is there anything else preventing me or any other reason I should avoid to put the chromium binary in the assets directory?
Maybe we can implement an option where the user can chose either to save the packages to the priv or assets directory so that the user is not only dependent on global install of npm packages and can use local installation?

I’d be happy to open up a pull-request if there are no other reasons (besides mix release) to not have the chrome binary in /assets.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement