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.createServer() exits if process.env.CI != 'true'

See original GitHub issue

Describe 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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
akvadrakocommented, Jul 13, 2021

Thanks for the quick fix 😃

1reaction
IanVScommented, Jul 13, 2021

@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.

Read more comments on GitHub >

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

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