Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code 127 - you may not have electron installed correctly #602

Closed
jamesaspence opened this issue Apr 26, 2016 · 37 comments
Closed

Code 127 - you may not have electron installed correctly #602

jamesaspence opened this issue Apr 26, 2016 · 37 comments

Comments

@jamesaspence
Copy link

jamesaspence commented Apr 26, 2016

I have done fresh installs of nightmare JS repeatedly, in an attempt to solve this issue. No dice.

I run npm i nightmare. It installs nightmare NPM version 3.3.6. It also installs electron for me. Electron-download NPM version 2.14.15 is installed, as well as electron-prebuilt NPM version 2.14.6.

Running it inside of my virtual box (running Ubuntu 14.04.3), it produces the error nightmare electron child process exited with code 127: command not found - you may not have electron installed correctly +8ms.

I have reinstalled multiple times. I've tried installing electron separately. No matter what I attempt, I always get that error.

I should point out, I can get the code to run perfectly on OSX. After I do a fresh reinstall outside of my virtual box, it works perfectly fine on OSX.

EDIT: Summary commands I have attempted:
npm uninstall electron && npm uninstall nightmare
npm i nightmare
npm i -g electron
npm i segmentio/nightmare

@yoz
Copy link
Contributor

yoz commented Apr 26, 2016

First off, your version numbers look like versions of NPM rather than versions of nightmare (latest is 2.3.4) or electron (latest is 0.37.7). You should only need to install nightmare, though.

Are you running the install commands inside your virtual box or on OSX? Nightmare has a dependency on electron-prebuilt, which downloads a platform-appropriate binary on install. So if you're installing on OSX but running on Linux it won't find the Linux binary.

@jamesaspence
Copy link
Author

I'm installing nightmare using npm i nightmare inside the virtual box. I did an uninstall of both electron and nightmare before that. All of this was done within the virtual box.

@jamesaspence
Copy link
Author

For versions: electron-download is 2.1.1, prebuilt is 0.37.7, and nightmare is 2.3.4

@yoz
Copy link
Contributor

yoz commented Apr 26, 2016

What do you have installed in node_modules/nightmare/node_modules/electron-prebuilt/dist?

Do you have any output from npm install?

@jamesaspence
Copy link
Author

jamesaspence commented Apr 26, 2016

Nothing inside of node_modules/nightmare/node_modules. That directory doesn't exist.

npm install outputs that the packages were installed correctly, from what I can tell. I can add the output here if you'd like to see it.

@jamesaspence
Copy link
Author

jamesaspence commented Apr 26, 2016

To give a lil more context, here's the sample code I have that's failing.

var Nightmare = require('nightmare');

var nightmare = Nightmare({
    show: false,
    webPreferences: {
        partition: 'custom'
    }
});

nightmare
    .goto('http://google.com')
    .evaluate(function () {
        return document.title;
    }).then(function (title) {
        console.log(title);
    });

That outputs:

nightmare queueing action "goto" for http://google.com +0ms
nightmare queueing action "evaluate" +5ms
nightmare running +7ms
nightmare electron child process exited with code 127: command not found - you may not have electron installed correctly +7ms

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 26, 2016

You may want to run with DEBUG=nightmare:*,electron:* to see output from electron, too. You might get some better details about why things are failing.

@jamesaspence
Copy link
Author

@Mr0grog Just tried that. Getting this error now:

electron:stderr /vagrant/code/node_modules/electron-prebuilt/dist/electron: error while loading shared libraries: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory +0m

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 26, 2016

Ok, so you are at least missing libgtk, which Electron needs to run. You may want to look at #224 for a better sense of all the binary dependencies you need when running on Linux.

@jamesaspence
Copy link
Author

jamesaspence commented Apr 26, 2016

I've got an update: I installed all the dependencies listed here: http://electron.atom.io/docs/v0.25.0/development/build-instructions-linux/

Now, my debug outputs literally nothing, even with DEBUG=nightmare:*,electron:* on. It just appears to exit silently.

Full command running:

clear && DEBUG=nightmare:*,electron:* node --harmony workbench.js

EDIT: I was running the command wrong. Now here's the error I'm getting:

nightmare queueing action "goto" for http://google.com +0ms
nightmare queueing action "evaluate" +7ms
nightmare running +1ms
nightmare electron child process exited with code 1: general error - you may need xvfb +246ms

However, xvfb is installed and the newest version?

EDIT 2: running xvfb-run node workbench.js works perfectly fine. Unfortunately, I need to run this as part of a node server process.

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 26, 2016

xvfb is installed and the newest version

Is it running? Generally you want to start Xvfb as a daemon process. Alternatively, you can xvfb-run [xvfb args] node your-nightmare-script.js

Additionally, if you don’t have a system well-configured for running headlessly, there are a bunch of other things you’ll want to ensure are configured and running properly. Check out the scripts in nightmare/test or bug @rosshinkley over on Gitter for more—he knows the ins-and-outs of the headless Linux issues much better than I.

Note also, if you are on Node v4+ (which is kind of a requirement now…?) you don’t need the --harmony flag anymore. (Though using it doesn’t hurt anything.)

@jamesaspence
Copy link
Author

@Mr0grog Do I need to? I was working under the assumption that nightmare would start the virtual display itself. Maybe that was my problem.

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 26, 2016

Do I need to?

Yes. In my experience, at least, it’s pretty unusual for any tool that uses an X Windows display to actually create one—the idea is usually that the program is simply asking the window server for a display to use (well, really a window to draw in, not even a display); it’s not really the program’s responsibility to worry about whether that display is real or virtual, how it’s managed, etc.

There was some brief discussion not too long ago (#502 (comment)) about whether it would be useful to do this automatically, but I don’t know that it’s gone anywhere.

@rosshinkley
Copy link
Contributor

Poking a head in:

There was some brief discussion not too long ago (#502 (comment)) about whether it would be useful to do this automatically, but I don’t know that it’s gone anywhere.

I've been working on this off and on, but hit a snag with Xvfb not reliably stopping when Electron stops. Still in the works if I can get it working properly.

@jamesaspence
Copy link
Author

Okay. I'm currently trying out Phantom+Casper+Spooky, seeing if that works a lil better. If I can't get that running, I'll probably switch back to nightmare again. I'll be sure to update this issue provided that doesn't go well.

@jamesaspence
Copy link
Author

jamesaspence commented Apr 27, 2016

Gave it a try again this morning. I'm using https://www.npmjs.com/package/xvfb to spin up my xvfb process prior to my code. However, I'm still getting nightmare electron child process exited with code 1: general error - you may need xvfb +56ms

EDIT: My code:

My code:

var Xvfb = require('xvfb');
var Nightmare = require('nightmare');

var xvfb = new Xvfb({
    silent: true
});
xvfb.startSync();

var nightmare = Nightmare({
    show: false,
    webPreferences: {
        partition: 'custom'
    }
});

nightmare
    .goto('https://google.com')
    .evaluate(function () {
        return document.title;
    })
    .end()
    .then(function (title) {
        console.log(title);
    });

xvfb.stopSync();

EDIT - using node headless also doesn't work. I still get nightmare electron child process exited with code 1: general error - you may need xvfb +0ms

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 27, 2016

Nightmare is async, so at least part of your problem is this:

xvfb.startSync();

Nightmare(...)
    .goto('https://google.com')
    .evaluate(function () {
        return document.title;
    })
    .end()
    .then(function (title) {
        console.log(title);
    });

// this stops xvfb before Nightmare even starts!
xvfb.stopSync();

Instead, you should be doing something more like:

xvfb.startSync();

Nightmare(...)
    .goto('https://google.com')
    .evaluate(function () {
        return document.title;
    })
    .end()
    .then(function (title) {
        console.log(title);
        // wait to stop xvfb until nightmare is actually finished
        xvfb.stop();
    })
    // and make sure to stop it even if something broke
    .catch(function() {
        xvfb.stop();
    });

@jamesaspence
Copy link
Author

No dice. Even with xvfb.stop done inside the then, or calling nightmare inside of the xvbp.start callback, I still get the error.

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 27, 2016

What’s the actual electron output?

@jamesaspence
Copy link
Author

Nothing. It just sits there. Using DEBUG=nightmare:*,electron:* node workbench.js yields nothing and the process just sits.

@Mr0grog
Copy link
Contributor

Mr0grog commented Apr 27, 2016

Using DEBUG=nightmare:,electron: node workbench.js yields nothing and the process just sits.

So… does it just sit, printing nothing, or does it print the error about Xvfb? If nothing, you’ve likely got some other issue, because that sounds like Electron isn’t even getting a chance to try and start.

@jamesaspence
Copy link
Author

jamesaspence commented Apr 27, 2016

@Mr0grog It literally just sits, printing nothing. Switching to DEBUG=nightmare node workbench.js shows me the nightmare log, which looks something like this:

nightmare queueing action "goto" for https://google.com +65ms
nightmare queueing action "evaluate" +1ms
nightmare running +0ms
nightmare electron child process exited with code 1: general error - you may need xvfb +25ms

I also get this error now:

Nightmare runner error:

    TypeError: Cannot read property 'dock' of undefined
        at Object.<anonymous> (/vagrant/code/node_modules/nightmare/lib/runner.js:54:29)
        at Module._compile (module.js:413:34)
        at Object.Module._extensions..js (module.js:422:10)
        at Module.load (module.js:357:32)
        at Function.Module._load (module.js:314:12)
        at loadApplicationPackage (/vagrant/code/node_modules/electron-prebuilt/dist/resources/default_app.asar/main.js:253:23)
        at Object.<anonymous> (/vagrant/code/node_modules/electron-prebuilt/dist/resources/default_app.asar/main.js:293:5)
        at Module._compile (module.js:413:34)
        at Object.Module._extensions..js (module.js:422:10)
        at Module.load (module.js:357:32)

EDIT: Never mind, now the original debug command is returning errors as well. Following output:

electron:stderr Xlib:  extension "RANDR" missing on display ":107". +0ms
electron:stderr App threw an error when running [TypeError: Cannot read property 'dock' of undefined] +186ms

EDIT 2: We're back to nothing after I tweaked my code again. No output, process just hangs forever.

var Xvfb = require('xvfb');
var Nightmare = require('nightmare');

var xvfb = new Xvfb({
    silent: true
});


var nightmare = Nightmare({
    show: false,
    webPreferences: {
        partition: 'custom'
    }
});

try {
    xvfb.start(function () {
        nightmare
            .goto('https://google.com')
            .evaluate(function () {
                return document.title;
            })
            .end()
            .then(function (title) {
                console.log(title);
                xvfb.stop();
            });
    });
} catch (e) {
    xvfb.stop();
}

This outputs nothing again. Changing to DEBUG=nightmare outputs:

nightmare queueing action "goto" for https://google.com +0ms
  nightmare queueing action "evaluate" +3ms
  nightmare running +3ms
  nightmare electron child process exited with code 1: general error - you may need xvfb +48ms

@rosshinkley
Copy link
Contributor

The following adapted from the example works on my headless box:

var Xvfb = require('xvfb');
var Nightmare = require('nightmare');

var xvfb = new Xvfb({
  silent: true
});
xvfb.startSync();

var nightmare = Nightmare({
  show: false,
  webPreferences: {
    partition: 'custom'
  }
});

nightmare
  .goto('https://google.com')
  .evaluate(function() {
    return document.title;
  })
  .end()
  .then(function(title) {
    console.log(title);
    xvfb.stopSync();
  });

Is that what your modification looks like/what you're running?

A couple of notes:

  • Nightmare construction must come after the Xvfb start. (It did here, but it's worth pointing out it's a requirement.) The Nightmare constructor automatically starts Electron and Xvfb should be running prior to that.
  • This log line: electron:stderr Xlib: extension "RANDR" missing on display ":107" makes it look like you might have other instances of Xvfb running. I've had Electron get a little flaky with multiple instances running (usually with regards to problems described in instance churn causes xvfb to occasionally hang #561). Might be worth a killall or a reboot to have a fresh start.

@jamesaspence
Copy link
Author

jamesaspence commented Apr 27, 2016

Okay, I'm basically starting from scratch. I re-provisioned my vagrant box. I'm reinstalling nightmare entirely via npm uninstall nightmare && npm i nightmare. I'm gonna be using node 5.5.0, npm 3.3.12.
EDIT: Also installed xvfb via sudo apt-get install xvfb
My code is gonna be exactly this:

var Xvfb = require('xvfb');
var Nightmare = require('nightmare');

var xvfb = new Xvfb({
    silent: true
});
xvfb.startSync();

var nightmare = Nightmare({
    show: false,
    webPreferences: {
        partition: 'custom'
    }
});

nightmare
    .goto('https://google.com')
    .evaluate(function () {
        return document.title;
    })
    .end()
    .then(function (title) {
        console.log(title);
        xvfb.stopSync();
    });

@jamesaspence
Copy link
Author

Result, even after all that:

nightmare queueing action "goto" for https://google.com +0ms
nightmare queueing action "evaluate" +9ms
nightmare running +8ms
nightmare electron child process exited with code 127: command not found - you may not have electron installed correctly +12ms

@rosshinkley
Copy link
Contributor

That's .... baffling. @yoz might have been on the right track, but the suggestion there looks like it would work for npm2, not npm3. If you look at node_modules/electron-prebuilt/dist, does electron exist there?

I'd also be curious if you explicitly installed electron-prebuilt and/or explicitly set electronPath if that might have any effect.

@paulintrognon
Copy link

paulintrognon commented May 19, 2016

I have the same issue, the weird thing is it works perfectly on my laptop, but within my vps I got the general error - you may need xvfb error. I am not using xvfb in my code, as I did not use it on my laptop and it worked. Is the use of xvfb needed on virtual servers ? If yes, could you explain why?

Thanks a lot :-)

EDIT: I ran the code provided by @jamesaspence and it's working, but i'm still willing not to use xvfb if I don't understand the need to use it - it worked without it before...

@rosshinkley
Copy link
Contributor

@paulintrognon You might want to take a look at #224. The short version is that Electron requires a framebuffer to render, and when you're running headlessly on Linux, running Xvfb satisfies that requirement.

@seliver
Copy link

seliver commented Jun 23, 2016

To solve this, I needed to install libxss.
Use this command to install it on ubuntu 14: sudo apt-get install libxss1

@rosshinkley
Copy link
Contributor

If you run with DEBUG=*, Electron should fail with helpful messages telling you what binary is missing, which should let you figure out what package needs to be installed. I suspect you're missing libxss or libnotify.

I'm going to go ahead and close this issue. If it crops up again, feel free to reopen/open a new issue.

@idchlife
Copy link

Hey guys, so for running nightmare in docker or server you need to install npm xvfb and always include it and use it?

@DonBras
Copy link

DonBras commented Oct 23, 2017

for getting electron run with xvfb on a headless ubuntu 16.04 system i needed to install following packages:
sudo apt install libasound2 libgconf-2-4 libgtk2.0-0 libxss1

@idchlife
Copy link

idchlife commented Nov 7, 2017

@jamesaspence after all this, did you solve this problem with nightmare or did you start using another library?

@jamesaspence
Copy link
Author

@idchlife I think (?) I got it working? Sorry I forgot to update this - I'll see if I can dig up some code. This was at a previous company so I'm not positive I'll be able to get access to the code and see how I resolved it.

@idchlife
Copy link

idchlife commented Nov 8, 2017

@jamesaspence thanks! Resolved it too.

For anyone looking to solve this you may need xvfb problem check

#224 (comment)

If you are using pm2 as I am, add env variable "DISPLAY": "xfvb_used_display_in_sh_script"

You need to use .sh script for every pm2-docker start or pm2 start command.

In this .sh script you will need FIRST to start xvfb then make pm2/pm2-docker start config.js (--only your_script if you want 1 script)

env variable with DISPLAY should be inside every script config in config.js

I after that you will run into permission denied error - increase docker shm_size to 1G or more if problem persists.

Man I spent way too much time trying to figure this out

@MikePonders
Copy link

MikePonders commented Jun 3, 2018

@DonBras That was a time saver!
For Debian Stretch on a Raspberry Pi 2 I also needed to add libnss3
This did it for me:
sudo apt install xvfb libasound2 libgconf-2-4 libgtk3.0-0 libxss1 libnss3

@xunter
Copy link

xunter commented Jan 29, 2020

You may want to run with DEBUG=nightmare:*,electron:* to see output from electron, too. You might get some better details about why things are failing.

In my case electron debug wrote: "electron: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory"
Googled, I found cmd and run that (electron/electron#1518 (comment)): apt-get install libgconf-2-4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

10 participants