Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite.createServer() exits if process.env.CI != 'true' #4196

Closed
6 tasks done
akvadrako opened this issue Jul 9, 2021 · 5 comments · Fixed by #4232
Closed
6 tasks done

vite.createServer() exits if process.env.CI != 'true' #4196

akvadrako opened this issue Jul 9, 2021 · 5 comments · Fixed by #4232

Comments

@akvadrako
Copy link

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

@akvadrako akvadrako changed the title vite.createServer() exists if process.env.CI != 'true' vite.createServer() exits if process.env.CI != 'true' Jul 9, 2021
@xhlsrj
Copy link

xhlsrj commented Jul 12, 2021

Same problem in Electron environment.

I use Vite's JavaScript APIs to create a server in my entry point. Then call electron to start it. It works with vite@2.3.8 but exits with vite@2.4.1 silently.

I compared the source code and found out the same code block makes it happened as process.env.CI is undefined.

@Shinigami92
Copy link
Member

Is this related to #4082?

@IanVS
Copy link
Contributor

IanVS commented 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.

@xhlsrj
Copy link

xhlsrj commented 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.

It works with vite 2.4.2. Thanks. Seems process.stdin.resume(); causes the end event.
Not in middleware mode. Simply as createServer(). Then get the server URL for loading.

@akvadrako
Copy link
Author

Thanks for the quick fix :)

@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this issue Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants