vite.createServer() exits if process.env.CI != 'true'
See original GitHub issueDescribe the bug
Today I spent a few hours tracking down some odd behavior in vite. I was using the dev server middleware like this:
const vitemw = await vite.createServer({
server: { middlewareMode: 'html' }
})
When I ran this within docker-compose run
it worked, but when I used docker-compose up
it would just immediately exit:
app0_1 | > node ./src/serve.js dev
app0_1 |
app0_1 | starting server; mode: dev
app0_1 | > Ready on localhost:3000~!
x_app0_1 exited with code 0
It turns out this was because of this block from vite:
if (process.env.CI !== 'true') {
process.stdin.on('end', exitProcess);
process.stdin.resume();
}
I suggest removing this block, as a middleware should not be causing a program exit in any case. It’s also undesirable behavior, since it may be running in a process with no stdin.
At the very least it shouldn’t die silently.
Reproduction
I think the snippet above makes it clear why this happens.
System Info
System:
OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
CPU: (8) x64 Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
Memory: 852.02 MB / 15.29 GB
Container: Yes
Shell: 5.1.4 - /bin/bash
Binaries:
Node: 15.11.0 - ~/.fnm/current/bin/node
npm: 7.6.0 - ~/.fnm/current/bin/npm
Browsers:
Chrome: 91.0.4472.77
Firefox: 89.0
npmPackages:
vite: ^2.4.1 => 2.4.1
Used Package Manager
npm
Logs
n/a
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
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Env Variables and Modes - Vite
Vite exposes env variables on the special import.meta.env object. ... Missing Semicolon or Unexpected token in this case, for example when "process.env.
Read more >Preview Options - Vite
Set to true to exit if port is already in use, instead of automatically trying the next available port. preview.https #. Type: boolean...
Read more >Server Options - Vite
Set to true to exit if port is already in use, instead of automatically trying the next available port. server.https #. Type: boolean...
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 via type:...
Read more >require is not defined vite | The Search Engine You Control
This can now also happen in Node.js as of version 14. ... path = require('path'); const {createServer} = require('vite'); const build = async...
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
Thanks for the quick fix 😃
@xhlsrj, are you running vite in middleware mode? Have you tested with vite 2.4.2? I believe it should work for you, since it includes #4082 as mentioned.