-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
nodemon -v: 1.18.6node -v: 11.2.0npm -v: 6.4.1yarn -v: 1.12.3- OS / terminal: Ubuntu 18.10 cosmic (linux x64) / Bash
- Command:
nodemon -r ./lib app
I'm running into an EADDRINUSE error with nodemon and express since yesterday, which only happens when requiring a module (or file) using -r from the CLI.
Expected behaviour
It should restart the web server when the entry file is saved.
Actual behaviour
It hangs up with Error: listen EADDRINUSE: address already in use when the file is saved.
Steps to reproduce
yarn init -yyarn add expressandyarn add -D nodemontouch app.jsandtouch lib.js(see file contents below)devscript inpackage.jsonwithnodemon -r ./lib appyarn dev
// app.js
require('express')().listen(3000, () => console.log('Works'))// lib.js - empty"scripts": {
"dev": "nodemon -r ./lib app"
},
"dependencies": {
"express": "^4.16.4"
},
"devDependencies": {
"nodemon": "^1.18.6"
}When I run yarn dev from the terminal, and then do Ctrl+S in app.js or lib.js in the editor, I get
yarn run v1.12.3
$ nodemon -r ./lib app
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node -r ./lib app index.js`
Works
[nodemon] restarting due to changes...
[nodemon] starting `node -r ./lib app index.js`
events.js:167
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1294:14)
at listenInCluster (net.js:1342:12)
at Server.listen (net.js:1429:7)
at Function.listen (/path/to/my/app/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/path/to/my/app/app.js:1:84)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1321:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:778:11)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)
[nodemon] app crashed - waiting for file changes before starting...The app boots correctly, but as soon as any file changes, nodemon can't restart it. In the meantime, the app still continues to run in the background. If I do Ctrl+C, it quits, but there's no more process on port 3000, so killing it by port fuser -k 3000/tcp doesn't do anything.
I found that
- it doesn't work with both
yarnandnpm, i.e.npm run devproduces the save error - it works when using
require('./lib')inapp.jsinstead of-rfrom the CLI - it works either way without
expressor any web server (because the port is not used) - same issue in Node
11.2.0,11.1.0, and10.13.0
I discovered this through esm when doing nodemon -r esm app, but later found out that it happens with any file. From that thread, the issue also seems to happen on MacOS as well. Tried rebooting, reinstalling Node, removing yarn.lock, then removing and re-installing node_modules, locking to older versions of nodemon, and express... I'm out of options here.
I scavenged many threads in this repo with this same error, but to no avail. I hope I'm posting in the right repo this time. Any help is appreciated, thanks!
P.S. Here's the dump with nodemon -r ./lib app --dump just in case.
Click to expand
> [email protected] dev /path/to/my/app
> nodemon -r ./lib app --dump
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
--------------
node: v11.2.0
nodemon: 1.18.6
command: /home/alex/.nvm/versions/node/v11.2.0/bin/node /path/to/my/app/node_modules/.bin/nodemon -r ./lib app --dump
cwd: /path/to/my/app
OS: linux x64
--------------
{ run: false,
system: { cwd: '/path/to/my/app' },
required: false,
dirs: [ '/path/to/my/app' ],
timeout: 1000,
options:
{ dump: true,
ignore:
[ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/ ],
watch: [ '*.*', re: /.*\..*/ ],
ignoreRoot:
[ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**' ],
restartable: 'rs',
colours: true,
execMap: { py: 'python', rb: 'ruby' },
stdin: true,
runOnChangeOnly: false,
verbose: false,
signal: 'SIGUSR2',
stdout: true,
watchOptions: {},
execOptions:
{ script: 'index.js',
exec: 'node',
args: [ '-r', './lib', 'app' ],
scriptPosition: 3,
nodeArgs: undefined,
execArgs: [],
ext: 'js,mjs,json',
env: {} },
monitor:
[ '*.*',
'!**/.git/**',
'!**/.nyc_output/**',
'!**/.sass-cache/**',
'!**/bower_components/**',
'!**/coverage/**',
'!**/node_modules/**' ] },
load: [Function],
reset: [Function: reset],
lastStarted: 0,
loaded: [],
watchInterval: null,
signal: 'SIGUSR2',
command:
{ raw:
{ executable: 'node',
args: [ '-r', './lib', 'app', 'index.js' ] },
string: 'node -r ./lib app index.js' } }
--------------