Laravel 9 现已切换到 vite,已达到文件观察者的 ENOSPC 限制

Pat*_*ros 1 laravel vite

从早期版本的 Jetstream 开始,我就一直在使用 Laravel 9。

\n

遵循vite 升级指南后,我运行了命令

\n
npm run dev\n
Run Code Online (Sandbox Code Playgroud)\n

我得到以下错误堆栈跟踪:

\n
VITE v3.0.7  ready in 282 ms\n\n  \xe2\x9e\x9c  Local:   http://localhost:5173/\n  \xe2\x9e\x9c  Network: use --host to expose\n\n  LARAVEL v9.24.0  plugin v0.5.3\n\n  \xe2\x9e\x9c  APP_URL: https://myproject.test\nnode:internal/errors:466\n    ErrorCaptureStackTrace(err);\n    ^\n\nError: ENOSPC: System limit for number of file watchers reached, watch \'/home/user/code/myproject/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat/PercentageFormatter.php\'\n    at FSWatcher.<computed> (node:internal/fs/watchers:244:19)\n    at Object.watch (node:fs:2306:34)\n    at createFsWatchInstance (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:47558:17)\n    at setFsWatchListener (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:47605:15)\n    at NodeFsHandler$1._watchWithNodeFs (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:47760:14)\n    at NodeFsHandler$1._handleFile (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:47824:23)\n    at NodeFsHandler$1._addToNodeFs (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:48066:21)\nEmitted \'error\' event on FSWatcher instance at:\n    at FSWatcher._handleError (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:49254:10)\n    at NodeFsHandler$1._addToNodeFs (file:///home/user/code/myproject/node_modules/vite/dist/node/chunks/dep-0f13c890.js:48074:18) {\n  errno: -28,\n  syscall: \'watch\',\n  code: \'ENOSPC\',\n  path: \'/home/user/code/myproject/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat/PercentageFormatter.php\',\n  filename: \'/home/user/code/myproject/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat/PercentageFormatter.php\'\n}\n\nNode.js v18.3.0\n\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的文件配置:

\n

vite.config.js

\n
import { defineConfig } from \'vite\';\nimport laravel from \'laravel-vite-plugin\';\n// import react from \'@vitejs/plugin-react\';\n// import vue from \'@vitejs/plugin-vue\';\n\nexport default defineConfig({\n    plugins: [\n        laravel({\n            input: [\'resources/css/app.css\', \'resources/js/app.js\'],\n            refresh: true,\n        }),\n    ],\n});\n
Run Code Online (Sandbox Code Playgroud)\n

postcss.config.js

\n
module.exports = {\n  plugins: {\n    tailwindcss: {},\n    autoprefixer: {},\n  },\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

tailwind.config.js

\n
const defaultTheme = require(\'tailwindcss/defaultTheme\');\n\nmodule.exports = {\n    content: [\n        \'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php\',\n        \'./vendor/laravel/jetstream/**/*.blade.php\',\n        \'./storage/framework/views/*.php\',\n        \'./resources/views/**/*.blade.php\',\n    ],\n\n    theme: {\n        extend: {\n            colors:{\n                primary: \'#B5A365\',\n                danger: \'#A8084D\',\n            },\n            fontFamily: {\n                sans: [\'Nunito\', ...defaultTheme.fontFamily.sans],\n            },\n        },\n    },\n\n    plugins: [require(\'@tailwindcss/forms\'), require(\'@tailwindcss/typography\')],\n};\n\n
Run Code Online (Sandbox Code Playgroud)\n

包.json

\n
{\n    "private": true,\n    "scripts": {\n        "dev": "vite",\n        "build": "vite build"\n    },\n    "devDependencies": {\n        "@tailwindcss/forms": "^0.4.0",\n        "@tailwindcss/typography": "^0.5.0",\n        "alpinejs": "^3.0.6",\n        "autoprefixer": "^10.4.8",\n        "axios": "^0.25",\n        "laravel-vite-plugin": "^0.5.3",\n        "lodash": "^4.17.19",\n        "postcss": "^8.4.16",\n        "postcss-import": "^14.0.1",\n        "tailwindcss": "^3.1.8",\n        "vite": "^3.0.7"\n    }\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

phpunit.xml

\n
<?xml version="1.0" encoding="UTF-8"?>\n<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"\n         bootstrap="vendor/autoload.php"\n         colors="true"\n>\n    <testsuites>\n        <testsuite name="Unit">\n            <directory suffix="Test.php">./tests/Unit</directory>\n        </testsuite>\n        <testsuite name="Feature">\n            <directory suffix="Test.php">./tests/Feature</directory>\n        </testsuite>\n    </testsuites>\n    <coverage processUncoveredFiles="true">\n        <include>\n            <directory suffix=".php">./app</directory>\n        </include>\n    </coverage>\n    <php>\n        <env name="APP_ENV" value="testing"/>\n        <env name="BCRYPT_ROUNDS" value="4"/>\n        <env name="CACHE_DRIVER" value="array"/>\n        <!-- <env name="DB_CONNECTION" value="sqlite"/> -->\n        <!-- <env name="DB_DATABASE" value=":memory:"/> -->\n        <env name="MAIL_MAILER" value="array"/>\n        <env name="QUEUE_CONNECTION" value="sync"/>\n        <env name="SESSION_DRIVER" value="array"/>\n        <env name="TELESCOPE_ENABLED" value="false"/>\n    </php>\n</phpunit>\n\n
Run Code Online (Sandbox Code Playgroud)\n

应用程序.css

\n
@tailwind base;\n@tailwind components;\n@tailwind utilities;\n
Run Code Online (Sandbox Code Playgroud)\n

我如何解决它?

\n

我缺少什么?

\n

解决了

\n

看起来现在正在工作。

\n

我所做的就是重新启动计算机,现在npm run dev它可以正常工作并且不会抛出任何错误:

\n
16:25:13 [vite] page reload resources/views/components/layouts/pages.blade.php (x3)\n
Run Code Online (Sandbox Code Playgroud)\n

Jou*_*ill 5

我过去遇到过这个问题,并使用这个答案来解决这个问题。

对于您的情况,重新启动可能会暂时解决问题,因为当您的计算机重新打开时,并非所有使用文件监视程序的程序都会重新启动。

在某些时候,如果您没有改变环境,您就会遇到同样的问题。要获得更永久的修复,请尝试我上面链接的答案:

如果您使用的是 Linux,您的项目将达到系统的文件监视程序限制

要解决此问题,请在您的终端上尝试:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)