ubuntu “笑话--观看”:错误:ENOSPC:已达到文件监视器数量的系统限制,监视

pkbketx9  于 2022-11-28  发布在  其他
关注(0)|答案(2)|浏览(170)

运行jest,首先不使用参数,然后使用--watch标志。

owner@G700:~/cp/projectName$ npm run test

> project_name@1.0.0 test /home/owner/cp/projectName
> jest

 PASS  src/classes/setupWizard/__tests__/SetupRole.test.ts
  ✓ SetupRole (4 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        5.335 s
Ran all test suites.

owner@G700:~/cp/projectName$ npm run test

> project_name@1.0.0 test /home/owner/cp/projectName
> jest --watch

internal/fs/watchers.js:186
    throw error;
    ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/owner/cp/projectName/node_modules/fast-json-stable-stringify/test'
    at FSWatcher.<computed> (internal/fs/watchers.js:178:26)                                                          
    at Object.watch (fs.js:1445:34)
    at NodeWatcher.watchdir (/home/owner/cp/projectName/node_modules/sane/src/node_watcher.js:159:22)
    at Walker.<anonymous> (/home/owner/cp/projectName/node_modules/sane/src/common.js:109:31)
    at Walker.emit (events.js:315:20)
    at /home/owner/cp/projectName/node_modules/walker/lib/walker.js:69:16
    at FSReqCallback.oncomplete (fs.js:163:23) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/home/owner/cp/projectName/node_modules/fast-json-stable-stringify/test',                        
  filename: '/home/owner/cp/projectName/node_modules/fast-json-stable-stringify/test'                     
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project_name@1.0.0 test: `jest --watch`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the project_name@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/owner/.npm/_logs/2020-06-05T00_30_53_889Z-debug.log

对于一个相当小的项目,什么会导致错误Error: ENOSPC: System limit for number of file watchers reached, watch
我运行的是Lubuntu 20.04,NodeJS 14.2.0,NPM 6.14.4。

// package.json

{
  "name": "project_name",
  "version": "1.0.0",
  "description": "",
  "main": "compiled/index.js",
  "scripts": {
    "test": "jest --watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.10.2",
    "@babel/preset-env": "^7.10.2",
    "@babel/preset-typescript": "^7.10.1",
    "@types/jest": "^25.2.3",
    "@types/node": "^14.0.5",
    "@types/readline-sync": "^1.4.3",
    "babel-jest": "^26.0.1",
    "jest": "^26.0.1",
    "ts-jest": "^26.0.0",
    "typescript": "^3.9.3"
  },
  "dependencies": {
    "@google-cloud/text-to-speech": "^2.3.0",
    "@google-cloud/translate": "^5.3.0",
    "readline-sync": "^1.4.10"
  },
  "jest" : {
    "preset" : "ts-jest"
    , "modulePathIgnorePatterns" : ["compiled"]
  }
}
flvlnr44

flvlnr441#

我在运行MX Linux 19.3,Node.js 14.15.1时遇到了同样的问题,但使用的是yarn而不是npm。
这与节点、jest或npm无关。
文件监视器监视所有文件,包括node_modules文件夹中的文件。因此,文件监视器的数量可能超过操作系统的默认配置。
在我的MX Linux中,允许的默认最大值是8192

$ sysctl -n fs.inotify.max_user_watches
8192

我使用以下命令将允许的最大值临时增加到20000

$ sudo sysctl -w fs.inotify.max_user_watches=20000 && sudo sysctl -p

在我做了配置更改后,jest --watch成功通过,没有出现错误。
然后,我检查了以下项使用的文件监视的数量:

$ find /proc/*/fd -user "$USER" -lname anon_inode:inotify -printf '%hinfo/%f\n' 2>/dev/null | xargs cat | grep -c '^inotify'
8207

显然,这比默认值8192多。
当我运行yarn start时,使用的文件监视的数量要多得多:

$ find /proc/*/fd -user "$USER" -lname anon_inode:inotify -printf '%hinfo/%f\n' 2>/dev/null | xargs cat | grep -c '^inotify'
17501

因此,20000在我看来是合理的。
为了使这个配置在系统重新启动后永久有效,我创建了一个具有所需限制的文件/etc/sysctl.d/10-user-watches.conf

fs.inotify.max_user_watches = 20000

它解决了问题。

更新

在另一个更大的项目中,文件手表的数量远远超过20000个。
因此,设置一个更高的限制可能更好,如80000左右。

echo fs.inotify.max_user_watches=80000 | sudo tee /etc/sysctl.d/10-user-watches.conf
hof1towb

hof1towb2#

我遇到了同样的问题,我修复了这个问题,通过删除现有的节点模块,我再次安装了节点模块,然后问题解决了。

相关问题