Program Tip

자동으로 파일 변경을 감지하지 못함

programtip 2020. 11. 12. 20:05
반응형

자동으로 파일 변경을 감지하지 못함


ng serve소스 파일이 변경 될 때마다 실행해야합니다 . 콘솔에 오류가 없습니다.

Angular CLI: 1.6.2
Node: 8.9.1
OS: linux ia32
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.0.2-c3d7cd9
@angular/cli: 1.6.2
@angular/material: 5.0.3-e20d8f0
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.2
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0

대부분의 경우 Linux에서 ng serve --watch또는 ng build --watch디렉토리에 충분한 권한이 없으면 작동하지 않습니다.

해결책은 필요한 권한을 제공하거나 sudo대신 사용하는 것입니다.

최신 정보

감시 플래그 ng serve는 기본 옵션이므로 실제로 중복됩니다. 실수를 지적한 @Zaphoid에게 감사드립니다.


ng serve --poll=2000

Linux 및 Windows에서 잘 작동


많은 수의 파일이있는 경우 Linux 에서 INotify Watches에 제한이 있음을 고려하십시오 . 예를 들어 시계 제한을 512K로 늘리면이 문제를 해결할 수 있습니다.

sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p --system

이전은 다시 시작한 후 손실되는 메모리 내 변경을 유발합니다.

그러나 다음 을 실행 하여 영구적으로 만들 수 있습니다 .

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system

참고로 https://github.com/angular/angular-cli/issues/8313#issuecomment-362728855https://github.com/guard/listen/wiki/Increasing-the-amount-를 확인할 수 있습니다. of-inotify-watchers


왜냐하면 변경을 감지하는 시스템은 기본적으로 너무 많은 감시를 처리 할 수 ​​없기 때문입니다.

그리고 해결책은 change the amount of watches다음을 수행해야합니다 (프로젝트에 포함될 최대 파일 수) run this command.

echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches

inotify의 문제는 컴퓨터를 다시 시작할 때마다이 카운터를 재설정하는 것입니다.


프로젝트에서 dist 폴더는 루트 소유입니다.

sudo ng serve대신 사용하십시오 ng serve.

또 다른 해결책

When there is having a large number of files watch not work in linux.There is a Limit at INotify Watches on Linux. So increasing the watches limit

//When live server not work in linux

sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p --system

ng serve //You can also do sudo **ng serve**

for people who use Windows the command ng serve --poll = 2000 works too.

ng serve --poll=2000


Only need to run sudo ng serve to resolve the issue.


This may help if it is the same problem I had. Trying to use ng serve and ng build --watch sometimes worked but mostly they were not watching for code changes and I thought it was something to do with ng.

Then I remembered a problem I had a while back with inotify watches

I ran this on my Ubuntu machine and it seems to have kicked in and watching code changes:

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system

credit goes to Scott Smith


I discovered that the dist/ folder in the project was owned by root. That is why sudo ng serve does see the changes when ng serve does not.

I removed the dist/ folder sudo rm -R dist/ and rebuild it as current user by starting the dev server ng serve and all worked again.


If all else fails, check your code for syntax errors - particularly on index.html, or parts of your code you recently edited just before this auto update broke. Syntax errors will break this auto update functionality in Angular.

In my case, I had multiple projects open in separate VS Code windows. On all my other projects, ng serve worked as expected: it auto updated on save. But on one project it would require a manual refresh to update. It ended up being because I had html comments outside of the defined HTML area of the template (so, the HTML comments came before <!doctype html>. So it was invalid bc it's HTML syntax outside of an HTML area.

I erased the comments and bam, auto update started working again (after one more manual refresh).

So go through index.html or other parts of your code you recently edited before this broke and one by one, cut sketchy parts out, do a refresh in the browser, then come back to VS Code and make a change, save and see if it auto updates.


I was having this problem on a new Linux Ubuntu install and noticed I was getting an error about 'too many watchers for limit' in VSCode at the same time. I followed the instructions to fix it in VSCode and it also fixed the issue with ng watch. More info here https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

I noticed people suggesting sudo to run watch. This is a dangerous game, you are giving npm packages root access to your system. If your permissions are correct, my issue could be your fix since the limit is per user, and by running as sudo, you are running as root instead of your current user that is past the limit (running a watch heavy ide like vscode or atom on ). If for some reason you have the wrong permissions, set them properly to your user / group with chown.


Doing the sudo ng serve command is a bad practice. You have to change the npm permission so that every time if you have to install some npm packages you don't have to use sudo.

This link can solve how to change npm permission to the current user and after following through this steps after you set the npm permission you can remove the node_modules folder from your project directory and use npm install. After completion of packages installation you can run ng serve and you don't have to do sudo ng serve every time you want to run your angular project.


I had the same problem, using sudo ng serve seemed to "solve" the problem unsatisfactorily. Using sudo is not satisfactory IMO.

I checked my INotify count versus my default limit (8192) using: lsof | grep inotify | wc -l The value returned by the above command was way less than the limit. So the INotify solution didn't seem to apply to my problem.

I also checked permissions and ownership, both seemed ok, comparable to another project that worked.

Out of frustration I restarted VS Code. Basically I closed all instances, I had two running and re-opened both following which the problem went away.

I am leaning towards a possible bug somewhere. This is something to consider before turning your system inside out. Fortunately/Unfortunately this problem hasn't occurred again, I'll dig deeper if it does.


You can try this too.

sudo ng serve

I don't recommend changing SO parameters. I've experienced some (lag) issues after changing fs.inotify.max_user_watches parameter since you will have other services running...

The "ng serve --poll=2000" is a good solution but you will probably forget this parameter...

Investigating: https://github.com/angular/angular-cli/wiki/angular-cli I'd done the following solution.

Changed de angular.json with poll parameter

"serve": {
   "builder....
   "options": {
        "browserTarget": "xkcd:build",
        "poll": 2000
   }
   ...

Works on My Machine :D


My answer may not be useful. but I search this question because of this.

After I bought a new computer, I forget to set auto save in the editor. Therefore, the code actually keep unchanged.


I would like to leave my case here, just for reference. In my case, the problem was on the system permissions. I used a shared folder inside a VM as a repo. I had no other message like permission denied or something. Tried everything and then I just realized that I was using a network drive.

참고URL : https://stackoverflow.com/questions/48092880/ng-serve-not-detecting-file-changes-automatically

반응형