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

Remix Vite Plugin watches server.watch.ignored files #10250

Open
janvogt opened this issue Nov 20, 2024 · 1 comment
Open

Remix Vite Plugin watches server.watch.ignored files #10250

janvogt opened this issue Nov 20, 2024 · 1 comment

Comments

@janvogt
Copy link

janvogt commented Nov 20, 2024

Reproduction

Checkout https://github.com/janvogt/remix-vite-watches-ignored-repro, run npm run dev and wait a couple of seconds.

See git log for the two changes from npx create-remix@latest.

System Info

I believe this issue can be reproduced on any linux system as long as /proc/sys/fs/inotify/max_user_watches is not extremly high, as the reproduction repo an equivalent ammount of folders and files to my real usecase. I hit this issue multiple times with:

$ cat /proc/sys/fs/inotify/max_user_watches 
122722

Here's the requested outpu nevertheless:

$ npx envinfo --system --npmPackages '{vite,@remix-run/*}' --binaries --browsers
System:
  OS: Linux 6.6 NixOS 24.05 (Uakari) 24.05 (Uakari)
  CPU: (8) arm64 Neoverse-N1
  Memory: 7.76 GB / 15.20 GB
  Container: Yes
  Shell: 3.7.1 - /run/current-system/sw/bin/fish
Binaries:
  Node: 20.18.0 - /nix/store/hsh74yzdb9yk834w9j5qz0w3sw84wcfv-nodejs-20.18.0/bin/node
  npm: 10.8.2 - /nix/store/hsh74yzdb9yk834w9j5qz0w3sw84wcfv-nodejs-20.18.0/bin/npm
npmPackages:
  @remix-run/dev: ^2.14.0 => 2.14.0 
  @remix-run/node: ^2.14.0 => 2.14.0 
  @remix-run/react: ^2.14.0 => 2.14.0 
  @remix-run/serve: ^2.14.0 => 2.14.0 
  vite: ^5.1.0 => 5.4.11 

Used Package Manager

npm

Expected Behavior

npm run dev should work, despite a deeply nested folder in the project directory. As long as this folder is server.watch.ignored.

Actual Behavior

npm run dev crashes with

$ npm run dev

> dev
> remix vite:dev

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
node:internal/fs/watchers:247
    const error = new UVException({
                  ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/dont_watch/8/8/52/5'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2490:36)
    at createFsWatchInstance (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42779:17)
    at setFsWatchListener (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42826:15)
    at NodeFsHandler._watchWithNodeFs (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42981:14)
    at NodeFsHandler._handleFile (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43045:23)
    at NodeFsHandler._addToNodeFs (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43287:21)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:44480:10)
    at NodeFsHandler._addToNodeFs (file:///home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43295:18) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/dont_watch/8/8/52/5',
  filename: '/home/jan/opensource/repro/remix-vite-watches-ignored-repro/clean-repro/dont_watch/8/8/52/5'
}

Node.js v20.18.0
@janvogt
Copy link
Author

janvogt commented Nov 20, 2024

Potential fix

Changing both of these lines:

plugin.ts:1053
plugin.ts:1273

from

watch: viteConfig.command === "build" ? null : undefined,

to

watch: viteConfig.command === "build" ? null : viteUserConfig.server?.watch,

fixes this issue.

I am unsure, though, wether this would have unintended side efects.

Context

I traced runtime mutations to vite config and found that server.watch.ignored is overwritten in the second line. The PR 8320 that introduced that line, didn't seem to intend this beaviour. In fact, it aimed to solve a similar problem #8313 of initentional watching during npm run build. Wheras completely disabling watching during build seems appropriate, doing so for npm run dev is not a solution, as it would break HMR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant