Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling file watchers for vite-node #5488

Closed
4 tasks done
danieldiekmeier opened this issue Apr 4, 2024 · 3 comments · Fixed by #6251
Closed
4 tasks done

Allow disabling file watchers for vite-node #5488

danieldiekmeier opened this issue Apr 4, 2024 · 3 comments · Fixed by #6251
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node

Comments

@danieldiekmeier
Copy link

danieldiekmeier commented Apr 4, 2024

Clear and concise description of the problem

I have a few .ts scripts that I run on my server. They are scripts that run through and then exit, so I don't need file watching. Of course, it wouldn't matter either way, but I started getting this error when the files in my project increased:

ENOSPC: System limit for number of file watchers reached

My limit was set to the default of 8192. This is already weird, because I only have ~604 files in my project, but whatever.

Suggested solution

I propose a flag like --no-watch that disables file watchers for cases where you don't need them.

Alternative

I'm currently solving this by setting server.watch: null in a dedicated vite-node.config.js to disable the watcher: https://vitejs.dev/config/server-options.html#server-watch

Additional context

No response

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 5, 2024

Actually server.watch: null is introduced for Vitest vitejs/vite#14208 and already used in some places

server: {
// disable watch mode in workspaces,
// because it is handled by the top-level watcher
watch: null,

Probably we can simply set server.watch: null automatically when there's no --watch

server: {
hmr: !!options.watch,
},

@dominictobias
Copy link

dominictobias commented Jul 25, 2024

I thought that run is supposed to run without watching but fails in Buildkite 🤔

$ vitest run --coverage
  | The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
  | Vitest  "deps.inline" is deprecated. If you rely on vite-node directly, use "server.deps.inline" instead. Otherwise, consider using "deps.optimizer.web.include"
  |  
  | RUN  v1.6.0 /var/lib/buildkite-agent/builds/buildkite-node20-builder-<redacted>/<redacted>
  | Coverage enabled with istanbul
  |  
  |  
  | ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
  | Error: ENOSPC: System limit for number of file watchers reached, watch '/var/lib/buildkite-agent/builds/buildkite-node20-builder-<redacted>/<redacted>/node_modules/<redacted>/charting_library/bundles/id_ID.5652.afa01acb54a69426de69.js'
  | ❯ FSWatcher.<computed> node:internal/fs/watchers:247:19
  | ❯ Object.watch node:fs:2491:36
  | ❯ createFsWatchInstance node_modules/chokidar/lib/nodefs-handler.js:119:15
  | ❯ setFsWatchListener node_modules/chokidar/lib/nodefs-handler.js:166:15
  | ❯ NodeFsHandler._watchWithNodeFs node_modules/chokidar/lib/nodefs-handler.js:331:14
  | ❯ NodeFsHandler._handleFile node_modules/chokidar/lib/nodefs-handler.js:395:23
  | ❯ NodeFsHandler._addToNodeFs node_modules/chokidar/lib/nodefs-handler.js:637:21
  |  
  | ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
  | Serialized Error: { errno: -28, syscall: 'watch', code: 'ENOSPC', path: '/var/lib/buildkite-agent/builds/buildkite-node20-builder-<redacted>/<redacted>/node_modules/<redacted>/charting_library/bundles/id_ID.5652.afa01acb54a69426de69.js', filename: '/var/lib/buildkite-agent/builds/buildkite-node20-builder-<redacted>/<redacted>/node_modules/<redacted>/charting_library/bundles/id_ID.5652.afa01acb54a69426de69.js' }

@sheremet-va sheremet-va added vite-node p2-edge-case Bug, but has workaround or limited in scope (priority) p3-minor-bug An edge case that only affects very specific usage (priority) and removed enhancement: pending triage p2-edge-case Bug, but has workaround or limited in scope (priority) labels Jul 25, 2024
@wmertens
Copy link

wmertens commented Jul 30, 2024

I'd like to add that exclude nor negative include seem to prevent this from happening. If you have a lot of files under your repo on Linux, you'll hit this.

The include/exclude should do early cutoff so that it doesn't descend into ignored directories.

UPDATE: in one repo, no issues with vitest v2, but in the other, still.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants