Всем привет.
После
npm run buildDev, а так же
npm start ошибку:
> node ./dist/server.js
events.js:182
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8080
at Object._errnoException (util.js:1041:11)
at _exceptionWithHostPort (util.js:1064:20)
at Server.setupListenHandle [as _listen2] (net.js:1322:14)
at listenInCluster (net.js:1370:12)
at Server.listen (net.js:1466:7)
at Function.listen (/home/vilkov/projects/aleton-express-webpack-1/node_modules/express/lib/application.js:618:24)
at eval (webpack:///./src/server/server-dev.js?:48:5)
at Object../src/server/server-dev.js (/home/vilkov/projects/aleton-express-webpack-1/dist/server.js:97:1)
at __webpack_require__ (/home/vilkov/projects/aleton-express-webpack-1/dist/server.js:20:30)
at /home/vilkov/projects/aleton-express-webpack-1/dist/server.js:84:18
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aleton-express-webpack-1@1.0.0 start: `node ./dist/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aleton-express-webpack-1@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vilkov/.npm/_logs/2018-11-27T13_26_35_680Z-debug.log
package.json:
"scripts": {
"test": "jest",
"coverage": "jest --coverage",
"buildDev": "rm -rf dist && webpack --mode development --config webpack.server.config.js && webpack --mode development --config webpack.dev.config.js",
"buildProd": "rm -rf dist && webpack --mode production --config webpack.server.config.js && webpack --mode production --config webpack.prod.config.js",
"start": "node ./dist/server.js"
},
server.js:
import path from 'path'
import express from 'express'
const app = express(),
DIST_DIR = __dirname,
HTML_FILE = path.join(DIST_DIR, 'index.html')
app.use(express.static(DIST_DIR))
app.get('*', (req, res) => {
res.sendFile(HTML_FILE)
})
const PORT = process.env.PORT || 8080
app.listen(PORT, () => {
console.log(`App listening to ${PORT}....`)
console.log('Press Ctrl+C to quit.')
})
Мне приходится каждый раз смотреть, чем занят порт:
sudo lsof -i :8080
и каждый раз грохать его, вызывая потом заново b>npm run buildDev и
npm startsudo kill -9 pid
Можно как-то это пофиксить, чтобы при рестарте не возникало ошибок, связанных с портом?
Спасибо!