Search code examples
node.jsvitevitest

"vitest --ui" causing "Error: spawn xdg-open ENOENT"


I'm trying to check out Vitest's fancy UI server in my node docker container. But can't get it up and running. When running the npm script vitest --ui I get a node error spawn xdg-open ENOENT.

Here the full error message:

$ npm run test-ui
> [email protected] test-ui
> vitest --ui


 DEV  v0.23.4 /home/node/apps/main/frontend
      UI started at http://localhost:51204/__vitest__/

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'https://localhost:51204/__vitest__/' ]
}

Node.js v18.10.0

Google is no help at all - nothing related to Vitest even close. Also I'm obviously not a Node.js expert.


Solution

  • Even though the Node.js error message appears pretty cryptic to me, I still was lucky to use Ubuntu as my primary OS (beside macOS) which made me draw my attention to xdg-open in the error message - I occasionally use the command to open all kind of programs/apps on Ubuntu. Don't know why, but you need to have xdg-open installed on your system, to be able to run vitest --ui, even though it's neither mentioned in Vitest nor in Vite Github repos with a single word. Anyway for debian based containers it's:

    apt install xdg-utils --fix-missing
    

    Allthough this made the ENOENT error go away and the UI server starts up without errors, I still don't get to see the UI app due to some runtime-dom errors... I give it up. But maybe someone else finds the xdg-open info helpful.

    UPDATE: It's working!

    I just had to append /__vitest__/ to my proxied local url as clearly described in the docs:

    "Then you can visit the Vitest UI at http://localhost:51204/__vitest__/"