Correción npm run build -- qt.qpa.xcb: could not connect to display


#1

1. Introducción

A continuación se describe solución para poder ejecutar npm run build en contexto donde se ejecutará desde un web hook o desde un terminal head-less (cron o similar).

2. Descripción del error y solución

  1. Si ejecutamos npm run build y obtenemos el siguiente mensaje de error:

    >> npm run build
    ...
    > build
    > vite build
    
    qt.qpa.xcb: could not connect to display 
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    
    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
    
    Aborted (core dumped)
    

    Este error es debido a que la herramienta pide/necesita tener acceso a un display (monitor) para funcionar.

  2. En este caso, se utilizar la herramienta xvfb-run. Para ello, la instalamos como administrador:

    >> apt-get install xvfb

  3. Y luego como usuario de la web, se ejecuta de nuevo el “npm run build” con:

    >> xvfb-run -a --server-args="-screen 0 1024x768x24" npm run build

3. Soluciones que no funcionan

  1. Confirmar que ejecutar la herramienta con la opción offscreen no resuelve el problema, generando el siguiente error:

    >> QT_QPA_PLATFORM=offscreen npm run build
    ...
    > build
    > vite build
    
    QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-prehopchancecom'
    (./src/core/Core.cpp l.710): Opening the file: build
    This plugin does not support propagateSizeHints()
    This plugin does not support propagateSizeHints()
    This plugin does not support setParent!
    ^C