question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vite does not shutdown properly when calling close() on the ViteDevServer

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
schalk-bcommented, Jul 2, 2021

I’ve taken a look, and I guess I don’t see where a call to process.exit() should happen when calling close(). If anything, the new behavior seems more correct, and it should be up to the overall parent process to determine when to end the process. In your reproduction, calling process.exit() after closing the server does end the process.

Edit: I’m still taking a look into this, because I’m not super-familiar with node.js conventions and expectations.

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.

1reaction
IanVScommented, Jul 2, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found