Node.JS: Getting error : [nodemon] Internal watch failed: watch ENOSPC
Javascriptnode.jsJavascript Problem Overview
I just installed Node.js
on my Ubuntu 14.04
operating system for the first time. I also installed npm
. The next step in my installation process was installing nodemon
. This all worked out fine.
But, when I run nodemon
by typing nodemon app.js
in my command line, I get the following error...
[nodemon] 1.8.1 [nodemon] to restart at any time, enter
rs[nodemon] watching: *.* [nodemon] starting
node app.js[nodemon] Internal watch failed: watch ENOSPC
In the command line below the error...
alopex@Alopex:~/Desktop/coding_dojo/week-9/javascript/node/testing_node$ Hello World
Why is this happening? Is this normal behavior for nodemon? If not, how can I fix it?
Side notes...
-
app.js
is aJavascript
file withconsole.log(111)
inside of it. -
node
version isv0.10.25
-
npm
version is1.3.10
-
nodemon
version is1.8.1
-
ubuntu
version is...Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS Release: 14.04 Codename: trusty
Javascript Solutions
Solution 1 - Javascript
It appears that my max ports weren't configured correctly. I ran the following code and it worked...
echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
What this command does is to increase the number of watches allowed for a single user. By the default the number can be low (8192 for example). When nodemon
tries to watch large numbers of directories for changes it has to create several watches, which can surpass that limit.
You could also solve this problem by:
sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p
But the way it was written first will make this change permanent.
Solution 2 - Javascript
On running node server shows Following Errors and solutions:
nodemon server.js
> [nodemon] 1.17.2
>
> [nodemon] to restart at any time, enter rs
>
> [nodemon] watching: .
>
> [nodemon] starting node server.js
[nodemon] Internal watch failed: watch /home/aurum304/jin ENOSPC
sudo pkill -f node
or
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Solution 3 - Javascript
Erik, You can just kill all the other node processes by
> pkill -f node
and then restart your server again. It'll work just fine then.
Solution 4 - Javascript
As per discussion over here, ENOSPC
means Error No more hard-disk space available
. Reason why this much memory required by nodemon
or gulp-nodemon
(in my case) is that it was watching contents of a folder which it shouldn't. To fix that nodemon has ignore
setting that can be used to tell nodemon what not to watch. Have a look at nodemon sample config here.
Solution 5 - Javascript
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
This worked for me
Solution 6 - Javascript
[nodemon] Internal watch failed: watch /home/Document/nmmExpressServer/bin ENOSPC
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `nodemon ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
This is the error I got when running nodemon ./bin/www
.
> The solution was closing an Atom window that had a entire directory of folders open in the project window.
I don't know why, but I'm assuming Atom and nodemon use similar processes to watch files/folders.
Solution 7 - Javascript
Try this....
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Solution 8 - Javascript
Add a nodemon.json
configuration file in your root folder and specify ignore patterns for example:
nodemon.json
{
"ignore": [
"*.test.js",
"dist/*"
]
}
- Note that by default
.git
,node_modules
,bower_components
,.nyc_output
,coverage
and.sass-cache
are ignored so you don't need to add them to your configuration.
Explanation: This error happens because you exceeded the max number of watchers allowed by your system (i.e. nodemon
has no more disk space to watch all the files - which probably means you are watching not important files). So you ignore non-important files that you don't care about changes in them for example the build output or the test cases.
Solution 9 - Javascript
in my case closing the visual studio code then starting the server did the trick
Operating system - ubuntu 16.4 lts
node.js version - 8.11.1
npm version - 6.0.0
Solution 10 - Javascript
Instead of specifying a list of directories to ignore (e.g. negative), you can also specify a list of directories to watch (e.g positive):
nodemon --watch dir1 --watch dir2 dir1/examples/index.js
In my particular case, I had one directory I wanted to watch and about nine I wanted to ignore, so specifying '--watch' was much simpler than specifying '--ignore'
Solution 11 - Javascript
If the operating system is Linux then just use it will work
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Solution 12 - Javascript
I had the same error, but in Ubuntu 14.04 inside Windows 10 (Bash on Ubuntu on Windows). All I did to overcome the error was to update the Creators update, which then allowed me to install 16.04 version of Ubuntu bash and then after installing newest version of node (by this steps) I installed also the newest version of npm and then the nodemon started to work properly.
Solution 13 - Javascript
Try reopening VS code or Atom with more specific directory where your app.js is present. I had a lot of folders opened and this problem occured. But once I opened my specific folder and tried once again, it worked.
Solution 14 - Javascript
There must be a better way of solving this, than what I suggest. I hope some experts land on this page. Also note that I was working on a development server and thus could afford to kill all processes of node. This may not be what you want.
I followed the answer of @zubair-alam and got it fixed for the first time. I added the "ignore" to the package.json (Even though the referred link says it is the default).
........ Before
"ignore": [
".git",
"node_modules/**/node_modules"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ./index.js --exec babel-node -e js"
},
........ After
However the error returned again as soon as I added a new file to the folder. I was working on Linux, so I basically killed all process related to node, by saying the following.
killall node
and then restarted npm by saying. The server started without errors.
npm start
You will have to change the killall command using a command specific to your operating system. See this discussion.