fraserxu / electron-pdf

📄 A command line tool to generate PDF from URL, HTML or Markdown files.
MIT License
1.23k stars 136 forks source link

"Error: Electron failed to install correctly" when using CLI #174

Open shankie-codes opened 7 years ago

shankie-codes commented 7 years ago

I used this package about six months ago without issue, but later versions (will report back with a since) seem to have the following error:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again

Quick test case:

docker run --rm -it --name test kipparker/docker-tape-run sleep 1000000 (just to get a quick test container up that has all the deps)

Connect into the container and npm install -g electron-pdf. Run an electron-pdf command, such as electron-pdf http://example.com ~/test.pdf

Results in something like:

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
    at Object.<anonymous> (/usr/local/lib/node_modules/electron-pdf/node_modules/electron/index.js:9:9)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/electron-pdf/cli.js:4:20)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
shankie-codes commented 7 years ago

Oops I think that this might be to me not initializing Xvfb... will report back

codecounselor commented 7 years ago

On a side note, what is the use case for doing this? (connecting into a running container and installing "stuff")? Wouldn't it be better to create a Dockerfile and build your own image with electron-pdf included?

shankie-codes commented 7 years ago

Yeah, it was just a quick and dirty. I was just hacking around trying to see what worked and what didn't without building again – the plan was to put it in a Dockerfile once I worked out what was going on.

The problem was definitely to do with Xvfb not being configured correctly. Could probably do with some more useful error messages in that case. I'll have a quick look tomorrow and see if I can figure out a solution

destegabry commented 7 years ago

I can't make it work on my headless Debian instances. I just followed the readme to init Xvfb but still getting the "Electron failed to install correctly" error... any ideas?

shankie-codes commented 7 years ago

Hmm from memory, I think that this was resolved (for me anyways) from a PR that someone else merged...

destegabry commented 7 years ago

I'm trying this on electron-pdf v1.3.0 that's the latest version right now

colinwoods commented 5 years ago

I had this problem as well on a fresh install on Ubuntu 18.04 with Node v8.10.0 and NPM 3.5.2.

I got it working by installing some additional packages and running electron/install.js after installing electron-pdf, see below:

$ sudo apt-get install xvfb xorg openbox libgtkextra-dev libgconf2-dev libnss3 libasound2 libxtst-dev libxss1 libxtst6 libgtk2.0-0
$ sudo npm install electron-pdf --global
$ cd /usr/local/lib/node_modules/electron-pdf/node_modules/electron/ && node install.js
$ sudo apt-get install xvfb # or equivalent 
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &

Then you it works on command line e.g.

$ electron-pdf http://mysite/file.html /tmp/output.pdf
codecounselor commented 5 years ago

Thanks @colinwoods, I don't know why I didn't share this earlier, but this is how I have my image configured.

FROM ubuntu:18.04

WORKDIR /app

RUN apt-get update && \
  apt-get install -y \
# v8 comes from apt
  nodejs npm \
# Required for Headless Electron/Chromium Rendering
  libgconf2-4 libxss1 libxtst6 libnss3 libasound2 xvfb dbus-x11 libgtk2.0-common \
# Get rid of files we don't need
  rm -rf /var/lib/apt/lists/* && \
# Get latest npm
  npm install -g npm

And while not required if only using electron-pdf I also use these packages (which may pull in other dependencies)

# Required for PDF -> PNG Conversion
  mupdf-tools \
# Used for PDF->PNG splitting by pdf2images-multiple
  poppler-utils && \