angular - 使用 Angular cli 禁用 watch node_modules

标签 angular webpack

我得到了著名的错误Error: ENOSPC: System limit for number of file watchers reached, watch 'frontend/node_modules/@angular/platform-b​​rowser/platform-b​​rowser.d.ts.__ivy_ngcc_bak'.

我认为问题是 webpack 正在监视 node_modules 文件。

我使用 linux,我有 fs.inotify.max_user_watches=1048576,但问题仍然存在。

当我删除 node_modules 并重建 el 项目时,它可以正常工作几个小时......

有什么方法可以排除 node_modules 以在 Angular 项目中观看?

最佳答案

我通过在 glob 中使用通配符将这个问题追踪到 angular.json 中的 Assets 复制:

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

在这种情况下,angular 监视父目录下的所有内容(包括 node_modules)。对我有用的是不使用通配符:

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

或在 prebuild(或 prestart)步骤中将必要的文件复制到 ./tmp 目录,然后使用:

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

当然,在后一种情况下,我不能简单地运行ng serve,但我需要有类似的东西:

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

在我的 package.json 中使用:npm run start 代替

另外,这个问题似乎是 Linux 特有的。在 Windows 上没有问题。

关于angular - 使用 Angular cli 禁用 watch node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65105060/

相关文章:

javascript - 无法使用构造函数填充 FormData

angular - Akita Observable OnCompleted 从不触发

css - 如何将 map 的高度固定为 Angular 4 中的屏幕尺寸

Angular FormGroup 在禁用时变脏

node.js - Gulp/NPM Dev依赖项-网站完成后如何处理?

javascript - 如何在 SCSS 中使用静态辅助函数 (javascript) 为不同环境的图像设置基本 url?

Angular 2.0.1 : router and canActivate class not working : No Directive annotation found on LoginGuard

css-loader localIdentName : is a hash necessary for uniqueness?

javascript - webpack 前端和后端都可以工作吗?

angular - 我希望我的 Angular 6 应用程序与 Google Jobs 一起工作,但无法正确格式化