steffenstein.com

ViteJs Docker fails to start

ViteJs xdg-open Error

2020-03-01

Lately i started a new VUE3 Js Project. And Vite.js comes up with an error.

Dockerfile

My Dockerfile looks like this:

FROM node:14-buster-slim
WORKDIR /usr/src/app
EXPOSE 3000
CMD npm install && npm run dev

Start Container fails with following error:

events.js:292
      throw er; // Unhandled 'error' event                                                                                                                           ^

Error: spawn xdg-open ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://localhost:3000/' ]

Solution:

ViteJs tries to open up a Web-browser, but my Docker container doesn't have one. Fix following in vite.config.js:

  server: {
    open: false,
  },

This will prevent ViteJs to pull up a Web-server.

Avatar of Steffen Stein

Hi, my name is Steffen 👋 I'm a webdeveloper from Cologne, Germany 🇩🇪 Coding abroad and traveling the world 🌎 ✈️