【问题标题】:Visual Studio Code: Unable to watch for file changes. Why?Visual Studio Code:无法监视文件更改。为什么?
【发布时间】:2019-11-11 18:03:48
【问题描述】:

我经常收到“Visual Studio Code 无法监视这个大型工作区中的文件更改”的错误,我不知道为什么。

Visual Studio Code (Linux): 1.24.1

我的排除设置是:

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true,
    "**/.svn/**": true,
    "**/dist/**": true,
    "**/dist-prod/**":true
}

项目的结构是:

angular.json
/dist
/dist-prod
/e2e
ngsw-config.json
/node_modules
package.json
package-lock.json
proxy.conf.json
README.md
/src
tsconfig.json
tslint.json
xliffmerge.json
.editorconfig
.gitignore
/.svn

/src 仅包含 167 个文件和文件夹。我怀疑 node_modules 并没有真正被排除在外。但我不能确定。我的设置正确吗?

VSC重启后问题就消失了,但过一会又总是出现...

【问题讨论】:

  • 我也经历过(并继续经历)这个问题。我打开了github.com/Microsoft/vscode/issues/59679
  • 不错的举动 Jack :-) 我使用了似乎是一般方法的解决方法,但感觉不对:stackoverflow.com/questions/50901127/…
  • 我也认为问题在于 node_modules 并没有真正被排除在外。安装新模块后我收到警告,不包括 node_modules 我的项目中只有大约 20 个文件。 Watcher exclude 设置为默认值,其中包括**/node_modules/**

标签: visual-studio-code


【解决方案1】:

你必须增加限制。请按照以下步骤操作:

  1. 检查电流限制cat /proc/sys/fs/inotify/max_user_watches
  2. 在 vim 编辑器中编辑 sysctl.conf 文件sudo vim /etc/sysctl.conf
  3. 在底部添加这一行fs.inotify.max_user_watches=524288
  4. 保存(esc):wq!
  5. 加载更改sudo sysctl -p
  6. 现在再次检查cat /proc/sys/fs/inotify/max_user_watches

如果计数相同,则执行以下命令

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

For more details

编码愉快:)

【讨论】:

  • 增加 max_user_watches 似乎是一种处理症状的方法。它不能治愈潜在的疾病。 15个月前,当我写这个问题时,我想知道“Watcher Exclude”功能是否有错误。我将它配置为排除 node_modules 和它应该忽略的其他文件夹。显然,在 167 个文件的小项目中没有必要增加 max_user_watches。当我查看输出时,在我看来,它通过的文件比这多得多……这个错误很可能被修复。有一天我会减少 max_user_watches 来检查它。
  • 默认情况下,几乎所有像 node_modules 这样的东西都添加到了监视排除列表中。是的,如果我们希望按照您的建议,显然我们可以包含更多项目。我们也可以禁用主动不需要的扩展。
  • 我真的不喜欢这是我能找到的唯一答案。我的项目有 3 个我真正想要观看的文件,我可以增加 max_user_watches 但对性能的影响很大。我的笔记本电脑已经 9 年了,它不需要额外的压力:/
猜你喜欢
  • 1970-01-01
  • 2019-03-04
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
  • 2010-09-25
  • 1970-01-01
  • 2015-07-16
  • 2021-04-03
相关资源
最近更新 更多