vitest
vitest copied to clipboard
[vite-node] Do not crash on error in watch mode
Clear and concise description of the problem
If you run vite-node in watch mode (e.g. vite-node -w app.ts
), any time your code crashes (e.g. saved with invalid syntax) you have to restart vite-node
manually.
Suggested solution
If an error (invalid syntax, code exception etc.) is encountered, do not stop the vite-node
process and wait for the next file change to rerun (potentially fixed) code.
Alternative
Running vite-node -w app.ts
manually every time you accidentally saved a file in an invalid state.
Additional context
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Same here when I add for example a console.log to index.ts the server crashes in watch mode:
$ vite-node -w ./src/server/index.ts
{"@timestamp":"2022-08-11T11:21:24.782Z","@message":"Node Environment: development","@fields":{"level":"info"}}
{"@timestamp":"2022-08-11T11:21:24.783Z","@message":"Server started at http://localhost:5555","@fields":{"level":"info"}}
{"@timestamp":"2022-08-11T11:21:24.783Z","@message":"Tokens served at http://localhost:5555/api/token","@fields":{"level":"info"}}
{"@timestamp":"2022-08-11T11:21:25.235Z","@message":"WebSocket connected","@fields":{"level":"info"}}
node:events:498
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5555
at Server.setupListenHandle [as _listen2] (node:net:1330:16)
at listenInCluster (node:net:1378:12)
at Server.listen (node:net:1465:7)
at Function.listen (C:\Users\user\GitHub\project1\node_modules\express\lib\application.js:635:24)
at ./src/server/index.ts:14:27
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ViteNodeRunner.directRequest (file:///C:/Users/user/GitHub/project1/node_modules/vite-node/dist/client.mjs:193:5)
at async ViteNodeRunner.cachedRequest (file:///C:/Users/user/GitHub/project1/node_modules/vite-node/dist/client.mjs:89:12)
at async ViteNodeRunner.executeId (file:///C:/Users/user/GitHub/project1/node_modules/vite-node/dist/client.mjs:77:12)
at async Promise.all (index 0)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1357:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 5555
}