【发布时间】:2020-10-08 17:33:30
【问题描述】:
这个问题似乎无处不在,但答案似乎并没有解决或回答我的情况。我刚刚开始使用 nodejs 和 react native,所以我安装了 nodejs 并运行了这些命令来开始:
$ npm install expo-cli
$ npm update
$ npx expo init helloWorld
我选择了“最小”的裸工作流,然后从 npx expo start 开始。 npx 找不到 expo-cli,所以我把 node_modules 目录改成 helloWorld 目录,然后用npx expo start 重新开始。这一次,项目启动正常,但立即给我一个关于超出观察者的错误,很可能是由于在添加 node_modules 目录后它试图观察大量文件:
internal/fs/watchers.js:186
throw error;
^
Error: ENOSPC: System limit for number of file watchers reached, watch '/home/drew/helloWorld/node_modules/css-tree'
at FSWatcher.<computed> (internal/fs/watchers.js:178:26)
at Object.watch (fs.js:1445:34)
at NodeWatcher.watchdir (/home/drew/helloWorld/node_modules/sane/src/node_watcher.js:159:22)
at Walker.<anonymous> (/home/drew/helloWorld/node_modules/sane/src/common.js:109:31)
at Walker.emit (events.js:315:20)
at /home/drew/helloWorld/node_modules/walker/lib/walker.js:69:16
at FSReqCallback.oncomplete (fs.js:163:23) {
errno: -28,
syscall: 'watch',
code: 'ENOSPC',
path: '/home/drew/helloWorld/node_modules/css-tree',
filename: '/home/drew/helloWorld/node_modules/css-tree'
}
我在这里搜索解决方案时发现的所有最佳答案都与 watchman 相关,但我没有安装它,而且 react native 似乎正在使用 fs.watch 代替。 one relevant question I found 表明没有办法像 watchman 那样添加忽略列表:
看起来不可能。只需查看侦听器中的路径,如果它以 'node_modules' 开头,则不执行任何操作。
它不会对性能造成太大影响,除非您在 node 运行时不断更新模块,这有点奇怪。
这不是我应该设置开发环境的方式吗?我想尽可能多地隔离项目(来自 python 其中 virtualenv 非常重要),但似乎它引入的问题比我预期的要多。如何在不求助于全局安装所有内容的情况下解决此问题?
【问题讨论】:
标签: node.js react-native watchman