Vite does not shutdown properly when calling close() on the ViteDevServer
See original GitHub issueDescribe the bug
I would expect after running this script that the process would end:
import { createServer } from 'vite'
const viteServer = await createServer()
await viteServer.close()
This is problematic when using the ViteDevServer with Jest as the process doesn’t end cleanly after the server is closed.
This was the commit that introduced the issue: https://github.com/vitejs/vite/commit/5999444496b6309460687b0769afad018aa21859
Reproduction
This was introduced in Vite 2.4.0-beta.0
https://github.com/schalk-b/vite-not-shutting-down
System Info
System:
OS: Windows 10 10.0.19041
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 16.06 GB / 31.92 GB
Binaries:
Node: 16.4.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
npm: 7.19.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1023.0), Chromium (91.0.864.59)
Internet Explorer: 11.0.19041.1
npmPackages:
vite: ^2.4.0-beta.0 => 2.4.0-beta.3
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Troubleshooting - Vite
Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js' #. The path to your project folder may include & , which doesn't work with npm on Windows...
Read more >JavaScript API - Vite
Vite's JavaScript APIs are fully typed, and it's recommended to use TypeScript or ... isRestart?: boolean): Promise<ViteDevServer> /** * Restart the server.
Read more >Server Options - Vite
Server Options #. server.host #. Type: string | boolean; Default: 'localhost'. Specify which IP addresses the server should listen on.
Read more >Configuring Vite
When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root. The most...
Read more >Configuring Vite
Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM, e.g. type:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It shouldn’t be necessary for a node process to call process.exit() for the process to end. If everything has been “cleaned up” and stopped. The process should end by itself.
It seems to be the addition of
process.stdin.resume()
that causes this issue. I think it can be removed without too much trouble. I put it in because a previous attempt had been made to add it.