Disable watch node_modules with Angular cli

Viewed 394

I get the famous error Error: ENOSPC: System limit for number of file watchers reached, watch 'frontend/node_modules/@angular/platform-browser/platform-browser.d.ts.__ivy_ngcc_bak'.

The problem I think is webpack is watching node_modules files.

I use linux, I have fs.inotify.max_user_watches=1048576 and the problem persists.

When I remove node_modules and rebuild el project, it works fine for a few hours...

Any way to exclude node_modules for watching in angular project?

1 Answers

I tracked down this problem to copying of assets in angular.json by using wildcard in glob:

{
 "input": "../",
 "glob": "*.md",
 "output": "./assets/"
}

in this case angular watches everything under parent directory (including node_modules). What worked for me was either not using wildcards:

{
 "input": "../",
 "glob": "README.md",
 "output": "./assets/"
}

or in prebuild (or prestart) step copying necessary files to ./tmp directory and then using:

{
 "input": "./tmp/",
 "glob": "*.md",
 "output": "./assets/"
}

Of course in the latter case I cannot run simply ng serve, but I need to have something like:

"start": "ng serve",
"prebuild":"mkdir -p tmp && cp ../*.md ./tmp/",
"prestart":"npm run prebuild",

in my package.json and use: npm run start instead

Also, it looks like this problem is particular to Linux. No problems on Windows.

Related