Reputation: 2093
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.
Upvotes: 6
Views: 6737
Reputation: 2493
If you are running your app in docker, make sure you open
set to false
in vite-config.ts
server: {
host: true,
port: 3000,
open: false
}
and package.json
only has "start": "vite"
or "start": "vite --no-open"
Upvotes: 0
Reputation: 4607
If you want to open the FE in a browser, do this:
sudo apt install xdg-utils
If you don't want to open the UI, like in a server, edit your package.json
file:
...
"scripts": {
"start": "vite --no-open",
...
}
...
Upvotes: 3
Reputation: 3042
I was running SveltKit with pnpm, vite, and vitest...
Got the same error message without vitest --ui
part ...
Solved by running it in docker without "--open"
CMD ["pnpm","run", "dev"]
Upvotes: 2
Reputation: 2093
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.
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__/
"
Upvotes: 5