-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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 startup 3000 port occupancy problem #7016
Comments
When starting another Vite project, Vite should technically detect that 3000 is occupied and try 3001 though 🤔 That's the behaviour I get currently with |
I tried and found the reason. When two projects are started, one specifies -- host and the other does not specify -- host will look like this. |
I used the same port service as the vite project to build the service with node, which caused a strange phenomenon. vite npm run dev -- --host node server import { createServer } from 'http'
const httpServer = createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
data: 'Hello World!'
}));
})
// const host = '192.168.1.101'
const host = 'localhost'
const strictPort = false
const port = 3000
const server = function () {
return new Promise((resolve, reject) => {
const onError = (e: Error & { code?: string }) => {
console.log('e', e)
if (e.code === 'EADDRINUSE') {
if (strictPort) {
httpServer.removeListener('error', onError)
reject(new Error(`Port ${port} is already in use`))
} else {
console.info(`Port ${port} is in use, trying another one...`)
httpServer.listen(++port, host)
}
} else {
httpServer.removeListener('error', onError)
reject(e)
}
}
httpServer.on('error', onError)
httpServer.listen(port, host, () => {
console.log('listening to', port)
httpServer.removeListener('error', onError)
resolve(port)
})
})
}
server() |
Seems a duplicate of #5241 (comment) |
Describe the bug
My computer has started a front-end project, and the listening port is 3000. When I start another vite project, it still occupies port 3000 and does not open other ports for me. As a result, when I access the 3000 port link, I access the vite project, but the previous project can't be accessed.
Reproduction
https://github.com/Brolly0204/vite-admin
System Info
macOS Monterey version 12.2.1 vite: "^2.8.0"
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: