Error: ENOSPC: System limit for number of file watchers reached,react native expo 开发启动时问题解决
在使用 react native expo 开发时,启动可能会遇到 Error: ENOSPC: System limit for number of file watchers reached 这样的问题,这是因为超出 系统用户可观测文件变更的数量 配置了,通过更改 fs.inotify.max_user_watches=524288 即可解决
问题表现
复制
展开
Error: ENOSPC: System limit for number of file watchers reached, watch 'xxx/node_modules/@ant-design/react-native/lib/steps'
at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
at Object.watch (node:fs:2551:36)
at NodeWatcher._watchdir (xxx/node_modules/metro-file-map/src/watchers/NodeWatcher.js:89:24)
at xxx/node_modules/metro-file-map/src/watchers/NodeWatcher.js:26:14
at Walker.<anonymous> (xxx/node_modules/metro-file-map/src/watchers/common.js:81:31)
at Walker.emit (node:events:507:28)
at xxx/node_modules/walker/lib/walker.js:69:16
at FSReqCallback.oncomplete (node:fs:189:23)
linux 解决方式
编辑配置文件:
复制
展开
sudo nano /etc/sysctl.conf
在最后加上:
复制
展开
fs.inotify.max_user_watches=524288
fs.inotify.max_user_instances=512
保存后执行:
复制
展开
sudo sysctl -p
windows 解决方式
在 metro.config.js
里添加:
复制
展开
const { getDefaultConfig } = require("expo/metro-config");
const config = getDefaultConfig(__dirname);
config.watchFolders = [
// 指定需要监听的目录,减少无用监听
];
config.resolver.blacklistRE = /.*\/node_modules\/(?!react-native|@react-native|expo).*/;
module.exports = config;
这样 Metro 就不会去监听所有 node_modules
,减少 watchers 占用。
作者:https://blog.xn--rpv331d.com/望舒
链接:https://blog.xn--rpv331d.com/望舒/blog/114
转载注意保留文章出处...
No data