To reproduce the issue, run:
npm run testIt should build the project, start a preview server on http://127.0.0.1:5050/, and list the files in the root directory when the server is running. But it fails with:
Full output
> [email protected] test
> npm run build && start-server-and-test preview http://127.0.0.1:5050/ ls
> [email protected] build
> tsc && vite build
vite v7.1.8 building for production...
✓ 7 modules transformed.
dist/index.html 0.46 kB │ gzip: 0.29 kB
dist/assets/index-BaiKPFAq.css 1.20 kB │ gzip: 0.62 kB
dist/assets/index-CW01TaJj.js 3.05 kB │ gzip: 1.64 kB
✓ built in 49ms
start-server-and-test initial parsed arguments { _: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] } +0ms
start-server-and-test named arguments: { expect: undefined, proxyHost: undefined, proxyUser: undefined, proxyPassword: undefined, proxyPort: undefined, proxyProtocol: undefined, '--expected': '--expect' } +0ms
start-server-and-test initial parsed arguments { _: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] } +0ms
start-server-and-test parsing CLI arguments: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] +0ms
start-server-and-test parsed args: { services: [ { start: 'npm run preview', url: [Array] } ], test: 'ls' } +1ms
1: starting server using command "npm run preview"
and when url "[ 'http://127.0.0.1:5050/' ]" is responding with HTTP status code 200
running tests using command "ls"
start-server-and-test single service "npm run preview" to run and test +0ms
start-server-and-test starting server with command "npm run preview", verbose mode? true +0ms
start-server-and-test starting waitOn [ 'http://127.0.0.1:5050/' ] +2ms
start-server-and-test wait-on options { resources: [ 'http://127.0.0.1:5050/' ], interval: 2000, window: 1000, timeout: 300000, verbose: true, strictSSL: true, log: true, headers: { Accept: 'text/html, application/json, text/plain, */*' }, validateStatus: [Function (anonymous)], proxy: undefined } +0ms
waiting for 1 resources: http://127.0.0.1:5050/
making HTTP(S) head request to url:http://127.0.0.1:5050/ ...
HTTP(S) error for http://127.0.0.1:5050/ Error: connect ECONNREFUSED 127.0.0.1:5050
> [email protected] preview
> vite preview --port 5050 --host 127.0.0.1 --strictPort
➜ Local: http://127.0.0.1:5050/
start-server-and-test getting child processes +181ms
start-server-and-test stopping child processes +30ms
start-server-and-test stopping server +0ms
start-server-and-test getting child processes +0ms
Error: server closed unexpectedly
at ChildProcess.onClose (/private/tmp/vite-bug-2/node_modules/start-server-and-test/src/index.js:83:14)
at ChildProcess.emit (node:events:519:28)
at maybeClose (node:internal/child_process:1101:16)
at ChildProcess._handle.onexit (node:internal/child_process:304:5)
Vite 7.1.7 works fine.
Full output with Vite 7.1.7
> [email protected] test
> npm run build && start-server-and-test preview http://127.0.0.1:5050/ ls
> [email protected] build
> tsc && vite build
vite v7.1.7 building for production...
✓ 7 modules transformed.
dist/index.html 0.46 kB │ gzip: 0.29 kB
dist/assets/index-BaiKPFAq.css 1.20 kB │ gzip: 0.62 kB
dist/assets/index-CW01TaJj.js 3.05 kB │ gzip: 1.64 kB
✓ built in 71ms
start-server-and-test initial parsed arguments { _: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] } +0ms
start-server-and-test named arguments: { expect: undefined, proxyHost: undefined, proxyUser: undefined, proxyPassword: undefined, proxyPort: undefined, proxyProtocol: undefined, '--expected': '--expect' } +0ms
start-server-and-test initial parsed arguments { _: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] } +0ms
start-server-and-test parsing CLI arguments: [ 'preview', 'http://127.0.0.1:5050/', 'ls' ] +1ms
start-server-and-test parsed args: { services: [ { start: 'npm run preview', url: [Array] } ], test: 'ls' } +0ms
1: starting server using command "npm run preview"
and when url "[ 'http://127.0.0.1:5050/' ]" is responding with HTTP status code 200
running tests using command "ls"
start-server-and-test single service "npm run preview" to run and test +0ms
start-server-and-test starting server with command "npm run preview", verbose mode? true +0ms
start-server-and-test starting waitOn [ 'http://127.0.0.1:5050/' ] +2ms
start-server-and-test wait-on options { resources: [ 'http://127.0.0.1:5050/' ], interval: 2000, window: 1000, timeout: 300000, verbose: true, strictSSL: true, log: true, headers: { Accept: 'text/html, application/json, text/plain, */*' }, validateStatus: [Function (anonymous)], proxy: undefined } +0ms
waiting for 1 resources: http://127.0.0.1:5050/
making HTTP(S) head request to url:http://127.0.0.1:5050/ ...
HTTP(S) error for http://127.0.0.1:5050/ Error: connect ECONNREFUSED 127.0.0.1:5050
> [email protected] preview
> vite preview --port 5050 --host 127.0.0.1 --strictPort
➜ Local: http://127.0.0.1:5050/
making HTTP(S) head request to url:http://127.0.0.1:5050/ ...
HTTP(S) result for http://127.0.0.1:5050/: {
status: 200,
statusText: 'OK',
headers: Object [AxiosHeaders] {
vary: 'Origin',
'content-type': 'text/html',
'cache-control': 'no-cache',
etag: 'W/"1c8-KrEcA5VDeJaDHLQsQVGILI/pwpA"',
date: 'Thu, 02 Oct 2025 11:15:58 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5'
},
data: ''
}
wait-on(10273) complete
start-server-and-test waitOn finished successfully +2s
start-server-and-test running test script command: ls +1ms
dist node_modules package.json README.md tsconfig.json
index.html package-lock.json public src
start-server-and-test getting child processes +11ms
start-server-and-test stopping child processes +36ms
start-server-and-test stopping server +0ms