在我开始之前,这不是这个问题的重复(错误:EMFILE:太多打开的文件 - React Native CLI ),因为尽管错误消息相同,但解决方案不起作用。我尝试了那里的所有解决方案——安装brew并运行brew命令(它不起作用——homebrew开始无限地安装东西,在我停止它之前占用了几GB的磁盘空间),将npm更新为从事该项目的其他人正在使用的版本等不起作用(也许我不知何故做得不正确?)
所以我最近加入了一个 React Native 和 Expo 项目。我在 macOS 上使用 vscode,并使用 --recursive 进行克隆。运行 npm i 后,这是我的 package.json:
{
"version": "1.0.0",
"main": "expo-router/entry",
"scripts": {
"start": "expo start",
"format": "npx prettier --write .",
"check": "npx prettier --check .",
"eslint": "npx eslint . --ext js --ext jsx",
"lint:fix": "eslint --fix --ext .js,.jsx .",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"prepare": "husky install"
},
"dependencies": {
"@expo/vector-icons": "^13.0.0",
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.17",
"eslint-config-prettier": "^9.1.0",
"expo": "~49.0.15",
"expo-app-loading": "^2.1.1",
"expo-constants": "~14.4.2",
"expo-font": "~11.4.0",
"expo-image": "~1.3.5",
"expo-linear-gradient": "~12.3.0",
"expo-linking": "~5.0.2",
"expo-router": "^2.0.0",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-dom": "^18.2.0",
"react-native": "0.72.10",
"react-native-email": "^2.1.0",
"react-native-gesture-handler": "~2.12.0",
"react-native-reanimated": "~3.3.0",
"react-native-responsive-fontsize": "^0.5.1",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-web": "^0.19.10",
"validator": "^13.11.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-react": "^7.33.2",
"husky": "^9.0.11",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0"
},
"private": true,
"resolutions": {
"metro": "0.76.0",
"metro-resolver": "0.76.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css,md}": [
"prettier --check",
"eslint --fix",
"git add"
]
}
}
然后,我运行 npx expo start -c。它适用于其他人的设备,但对我来说这似乎是
› Press s │ switch to development build
› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web
› Press j │ open debugger
› Press r │ reload app
› Press m │ toggle menu
› Press o │ open project code in your editor
› Press ? │ show all commands
Logs for your project will appear below. Press Ctrl+C to exit.
node:events:496
throw er; // Unhandled 'error' event
^
Error: EMFILE: too many open files, watch
at FSWatcher._handle.onchange (node:internal/fs/watchers:207:21)
Emitted 'error' event on NodeWatcher instance at:
at FSWatcher._checkedEmitError (/Users/shiqizhou/github projects/Front-End/node_modules/metro-file-map/src/watchers/NodeWatcher.js:134:12)
at FSWatcher.emit (node:events:518:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:213:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
Node.js v20.12.1`
我不知道该怎么办。 在我看来,这个问题主要只适用于 macOS 和 xcode 上的人,但对我来说,它发生在 vscode 上。我不确定这是否是有用的信息。
任何后续问题、解答、意见、建议,我们将不胜感激!
我遇到了同样的问题,并尝试了所有常见建议的解决方案,但没有成功。但是,我找到了一个对我有用的解决方案:
透明守望者手表:
我运行了以下命令来清除所有手表和关联的触发器:
watchman watch-del-all
此命令删除所有文件监视,解决“打开文件过多”的问题。在尝试了许多其他没有帮助的解决方案后,它对我来说非常有效。