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

--watch throws "address already in use" error #2587

Closed
6 tasks done
dionsaur84 opened this issue Dec 31, 2022 · 2 comments
Closed
6 tasks done

--watch throws "address already in use" error #2587

dionsaur84 opened this issue Dec 31, 2022 · 2 comments

Comments

@dionsaur84
Copy link

Describe the bug

I'm trying to use vite for frontend and vite-node for backend

In dev, I would like:

  • vite to watch files and rebuild the frontend on changes
  • vite-node to watch files and restart the server on changes

For example, here is my dev script inside of package.json:

"scripts": {
    "dev": "vite build --watch && vite-node ./src/entries/server.js --watch"
},

Here is my vite.config.js file:

import reactPlugin from '@vitejs/plugin-react'
import { defineConfig } from 'vite'

export default defineConfig({
    build: {
        rollupOptions: {
            input: './src/entries/client.jsx',
            output: {
                entryFileNames: '[name].js',
                assetFileNames: '[name].[ext]',
            },
        },
        outDir: './public/dist',
    },
    publicDir: false,
    plugins: [
        reactPlugin(),
    ],
})

The ./src/entries/server.js file just starts an express server:

import app from '../lib/app'
import env from '../lib/env'

app.listen(env.APP_PORT, function () {
    console.log(`app listening on http://localhost:${env.APP_PORT}`)
})

Ideally I would like HMR to work with this as well. Perhaps I am doing this the wrong way, but right now, when I run the dev command and edit a file, vite-node gives the following error:

[vite-node] Failed to execute file: 
 Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1468:16)
    at listenInCluster (node:net:1516:12)
    at Server.listen (node:net:1604:7)
    at Function.listen (/Users/dionsaur84/Sites/dio-framework/node_modules/express/lib/application.js:635:24)
    at /Users/dionsaur84/Sites/dio-framework/src/entries/server.js:10:5
    at ViteNodeRunner.directRequest (file:///Users/dionsaur84/Sites/dio-framework/node_modules/vite-node/dist/client.mjs:289:5)
    at ViteNodeRunner.cachedRequest (file:///Users/dionsaur84/Sites/dio-framework/node_modules/vite-node/dist/client.mjs:149:14)
    at ViteNodeRunner.executeFile (file:///Users/dionsaur84/Sites/dio-framework/node_modules/vite-node/dist/client.mjs:126:12)
    at CAC.run (file:///Users/dionsaur84/Sites/dio-framework/node_modules/vite-node/dist/cli.mjs:678:5) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}

Reproduction

Please see description.

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 517.83 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.2.0 - /opt/homebrew/bin/node
    npm: 8.19.3 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Safari: 16.2

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

Duplicate of #2334

@sheremet-va sheremet-va marked this as a duplicate of #2334 Dec 31, 2022
@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Dec 31, 2022
@dionsaur84
Copy link
Author

my bad, thank you

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants