coletiv / puppeteer-pdf

PDF generation wrapper for Elixir using Puppeteer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chromium revision is not downloaded

DennisKh opened this issue · comments

(node:14878) UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install"
at Launcher.launch (/usr/local/lib/node_modules/puppeteer-pdf/node_modules/puppeteer/lib/Launcher.js:119:15)
at <anonymous>
(node:14878) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14878) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Hi DennisKh, can you provide more information ? Did you run npm i puppeteer-pdf -g ? Normally when installing puppeteer-pdf it will download the chromium browser.

After npm i puppeteer-pdf -g I got this error. There was an error before that:

[error] Task #PID<0.922.0> started from #PID<0.920.0> terminating
** (stop) :enoent
    :erlang.open_port({:spawn_executable, '/var/www/elixir/elixir_billing/deps/puppeteer_pdf/lib/puppeteer_pdf'}, [:use_stdio, :exit_status, :binary, :hide, {:args, ["/var/www/elixir/elixir_billing/lib/elixir_billing_web/templates/bank_cards/index2.html", "--path", "/var/www/elixir/elixir_billing/index.pdf", "--marginLeft", "40", "--marginRight", "40", "--marginTop", "40", "--marginBottom", "150", "--format", "A4", "--printBackground", "--displayHeaderFooter", "--debug"]}])
    (elixir) lib/system.ex:641: System.cmd/3
    (puppeteer_pdf) lib/generate.ex:179: anonymous fn/2 in PuppeteerPdf.Generate.from_file/3
    (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: #Function<1.83883354/0 in PuppeteerPdf.Generate.from_file/3>
    Args: []
[error] Ranch protocol #PID<0.920.0> of listener ElixirBillingWeb.Endpoint.HTTP (connection #PID<0.919.0>, stream id 1) terminated
** (exit) :enoent

When I installed the puppeteer-pdf, I saw how the chromium was installed

:enoent means that it couldn't found the puppeteer_pdf binary. With the -g it would be installed globally, something like /usr/local/bin/puppeteer-pdf. Please check where it was installed.

I fixed error with :enoent but I still have error with chromium

For some reason, the new version of the puppeteer-pdf (the node dependency) doesn't download Chromium. I'm checking why it doesn't ...

Installing an older version seems to fix the issue, npm i --save puppeteer@1.2.0 -g but don't know why it doesn't download chromium in the new version (1.4.0).

Ok, appears to be in a separate package, https://github.com/GoogleChrome/puppeteer#puppeteer-core.

I will update readme to let people know how to use the new version.

Not sure if the comment above solved the issue, but you should copy the .local-chromium folder from the puppeteer to inside the puppeteer-pdf. Something like this.

cp -R puppeteer/.local-chromium/ /usr/local/lib/node_modules/puppeteer-pdf/node_modules/puppeteer/

You can run find / -name ".local-chromium" to find where it is.

Thank you very much for the detailed instructions. Everything works. But I need advice. How to connect css file? I tried to prescribe styles in the html but they did not render.

Not sure I understand what is your issue. I've used with in-line styling (not really sure why right now), but I've tested with a html file and a css file and it works.

index.html

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <h1>H1</h1>
    <p>Hello there</p>
  </body>
</html>
body {
  font-weight: bold;
  font-size: 50px;
}

puppeteer-pdf index.html --path xpto.pdf

I got with this. It was not a issue. It was my mistake when i tried to render view.

Don't know yet why the behaviour of this bug, but another solution is to remove the puppeteer folder inside the node_modules folder that is inside of puppeteer-pdf. If you install both puppeteer and puppeteer-pdf you don't need that one inside puppeteer-pdf.

I am still having this problem installing puppeteer-pdf with sudo npm i puppeteer-pdf -g on Ubuntu 18.04 (Beaver). Installing puppeteer with sudo npm i puppeteer -g afterwards downloaded chromium, but then threw UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install" when I tried using puppeteer-pdf

Did you try copy the .local-chromium folder as explained here ?