Vite dev server causes EMFILE when used as Playwright webServer in projects with large node_modules\n\nWhen Playwright's webServer launches vite in dev mode, chokidar's file watcher attempts to watch all files. On Linux with large dependency trees, this exhausts inotify watchers causing EMFILE errors even when ulimit is high. The crash happens during startup before any test runs.
Use vite preview (static file server) instead of vite dev as the Playwright webServer. This serves dist/ without file watchers.\n\nIn playwright config:\nts\nwebServer: {\n command: \"npx vite preview --port 5775 --strictPort\",\n port: 5775,\n timeout: 120_000,\n reuseExistingServer: !process.env.CI,\n}\n\n\nRun the build step before E2E tests. This is arguably better practice anyway since it tests the production bundle.\n\nCaveat: dev-only Vite plugins using configureServer (e.g., custom headers for COOP/COEP) won't apply in preview. Add configurePreviewServer to make them work in both modes:\n\nts\nfunction myPlugin(): Plugin {\n return {\n name: 'my-plugin',\n configureServer(server) { server.middlewares.use(handler); },\n configurePreviewServer(server) { server.middlewares.use(handler); },\n };\n}\n