MagicMirror² v2.5.0 is available! For more information about this release, check out this topic.

Electron Error: Cannot open display :0



  • Dear all,
    I have tried to setup MM2 about 20 times by now and always run into exactly the same error:

    pi@MirrorPi:~ $ cd MagicMirror/
    pi@MirrorPi:~/MagicMirror $ DISPLAY=:0 npm start
    
    > magicmirror@2.5.0 start /home/pi/MagicMirror
    > sh run-start.sh
    
    (electron:24936): Gtk-WARNING **: cannot open display: :0
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! magicmirror@2.5.0 start: `sh run-start.sh`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the magicmirror@2.5.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/pi/.npm/_logs/2018-10-03T21_35_33_903Z-debug.log
    

    The Log-File states:

    info it worked if it ends with ok
    1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
    2 info using npm@6.4.1
    3 info using node@v10.11.0
    4 verbose run-script [ 'prestart', 'start', 'poststart' ]
    5 info lifecycle magicmirror@2.5.0~prestart: magicmirror@2.5.0
    6 info lifecycle magicmirror@2.5.0~start: magicmirror@2.5.0
    7 verbose lifecycle magicmirror@2.5.0~start: unsafe-perm in lifecycle true
    8 verbose lifecycle magicmirror@2.5.0~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/pi/MagicMirror/node_modules/.bin:/usr/local/sb$
    9 verbose lifecycle magicmirror@2.5.0~start: CWD: /home/pi/MagicMirror
    10 silly lifecycle magicmirror@2.5.0~start: Args: [ '-c', 'sh run-start.sh' ]
    11 silly lifecycle magicmirror@2.5.0~start: Returned: code: 1  signal: null
    12 info lifecycle magicmirror@2.5.0~start: Failed to exec start script
    13 verbose stack Error: magicmirror@2.5.0 start: `sh run-start.sh`
    13 verbose stack Exit status 1
    13 verbose stack     at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
    13 verbose stack     at EventEmitter.emit (events.js:182:13)
    13 verbose stack     at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
    13 verbose stack     at ChildProcess.emit (events.js:182:13)
    13 verbose stack     at maybeClose (internal/child_process.js:962:16)
    13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
    14 verbose pkgid magicmirror@2.5.0
    15 verbose cwd /home/pi/MagicMirror
    16 verbose Linux 4.14.70-v7+
    17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
    18 verbose node v10.11.0
    19 verbose npm  v6.4.1
    20 error code ELIFECYCLE
    21 error errno 1
    

    My setup process is:

    • clean install of latest image of Raspian stretch
    • setup wifi, keyboard, CLI-boot
    • sudo apt-get update && sudo apt-get upgrade
    • set memory-split to 256
    • activate Fake KMS
    • install latest versions of NodeJS (via apt-get) and npm (via npm)
    • install MM2 via raspberry.sh script

    I do not get any error messages during setup.

    I also tried the manual setup several times with the same result and even tried different Pis, SD cards and Monitors. Setting up the system on-site or via SSH does not make a difference either.

    Searching the internet did not get me very far. What I tried without success:

    • export DISPLAY=":0.0"
    • export DISPLAY=":0"
    • xhost +–> unable to open display “:0”
    • xhost local:root --> unable to open display “:0”
    • xhost +localhost --> unable to open display “:0”
    • adding Defaults env_keep=DISPLAY in /etc/sudoers
    • adding export XAUTHORITY=$HOME/.Xauthority in /home/pi/.bashrc

    Do you have any idea how to solve this?



  • I had the same error, and the problem turned out to be that on first boot I had decided to reconfigure the pi to boot to the console rather than the desktop. Consequently I didn’t have a x server running (doh!)
    You didn’t mention that as one of your setup steps, but I though it might be worth mentioning.



  • @rudibarani said in Electron Error: Cannot open display :0:

    setup wifi, keyboard, CLI-boot

    you ARE running the GUI desktop, right… NOT commandline.



  • I am now 🙂



  • @bream @sdetweil Thank you very much for your reply! This could be the right path! I have initially configured the Pi on the GUI surface (Wifi, Keyboard) and then switched to CLI boot. I have done this with my previous installations of MagicMirror without problems, as electron started the x-server as needed. This does not seem to work anymore…

    How do I revert this? I have changed back from CLI-boot to Desktop GUI in raspi-config. If I ssh into the pi and start MagicMirror via DISPLAY=:0 npm start, the application claims to start without problems:

    > magicmirror@2.5.0 start /home/pi/MagicMirror
    > sh run-start.sh
    
    Starting MagicMirror: v2.5.0
    Loading config ...
    Loading module helpers ...
    No helper found for module: alert.
    Initializing new module helper ...
    Module helper loaded: updatenotification
    No helper found for module: clock.
    Initializing new module helper ...
    Module helper loaded: calendar
    No helper found for module: compliments.
    No helper found for module: currentweather.
    No helper found for module: weatherforecast.
    Initializing new module helper ...
    Module helper loaded: newsfeed
    All module helpers loaded.
    Starting server on port 8080 ... 
    Server started ...
    Connecting socket for: updatenotification
    Connecting socket for: calendar
    Starting node helper for: calendar
    Connecting socket for: newsfeed
    Starting module: newsfeed
    Sockets connected & modules started ...
    Launching application.
    

    Unfortunately, the display still just shows the GUI of the operation system.
    Could you please help me from here?

    Thank you very much!



  • @rudibarani i only do npm start from my ssh session

    do u have a keyboard on the pi? if so, ctrl-alt-t will open a shell window… then u should be able to get to the previous command with up arrow…