question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
colinwoodscommented, Jan 16, 2019

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
0reactions
codecounselorcommented, Jan 16, 2019

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 && \
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Electron failed to install correctly, please delete ... - GitHub
I can not use Electron because it is not installed correctly, ... }\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
Read more >
Electron failed to install correctly, please delete node_modules
Make sure to delete node_modules folder and run yarn cache clean or npm cache verify to make sure the cache is healed from...
Read more >
Error: Electron failed to install correctly, please delete ...
Are you stumbling in that error message: Electron failed to install correctly, please delete node_modules/electron and try installing again ...
Read more >
MM Ver.2.21 Electron failed to install error - MagicMirror Forum
I just updated to ver 2.21. MM crashed and no longer working. npm start shows error magicmirror@2.21.0 start DISPLAY=“${DISPLAY:=:0}” .
Read more >
Advanced Installation Instructions | Electron
In almost all cases, these errors are the result of network problems and not actual issues with the electron npm package. Errors like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found