Skip to content

turn off file watchers #1327

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

evertbouw
Copy link

I thought I was running into this problem laravel/vite-plugin#152 but it was happening in prod builds, so none of the suggestions worked. I traced where the watchers were coming from and it was vanilla-extract. I patched in watch: null in my project and now CI/CD builds are working again.

Copy link

changeset-bot bot commented Feb 16, 2024

🦋 Changeset detected

Latest commit: f39c1b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@vanilla-extract/integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mrm007
Copy link
Contributor

mrm007 commented Feb 19, 2024

Thanks @evertbouw!

Is your project public or do you have a way to reproduce this? I might write an integration test for the compiler if it's something that can be automated.

@evertbouw
Copy link
Author

@mrm007 Sorry it's proprietary. I'm guessing if you create more files than the system filewachter limit you should run into this, doesn't seems to happen in macos locally but it did on the linux CI/CD box.

@askoufis
Copy link
Contributor

I wonder if perhaps we're creating multiple compilers, instead of re-using the existing one.
@evertbouw Could you try out this snapshot version of the vite plugin from #1397? 0.0.0-fix-watch-mode-20240429115131.

@evertbouw
Copy link
Author

evertbouw commented May 2, 2024

@askoufis that did not fix the problem.

devDependencies:
- @vanilla-extract/vite-plugin 4.0.9
+ @vanilla-extract/vite-plugin 0.0.0-fix-watch-mode-20240429115131 (4.0.9 is available)

Done in 14.1s

> vite build

vite v5.2.11 building for production...
transforming...
node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/forge/application/vendor/nesbot/carbon/src/Carbon/Lang/dua.php'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2418:34)
    at createFsWatchInstance (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44360:17)
    at setFsWatchListener (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44407:15)
    at NodeFsHandler._watchWithNodeFs (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44562:14)
    at NodeFsHandler._handleFile (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44626:23)
    at NodeFsHandler._addToNodeFs (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44868:21)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:46061:10)
    at NodeFsHandler._addToNodeFs (file:///home/forge/application/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:44876:18) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/home/forge/application/vendor/nesbot/carbon/src/Carbon/Lang/dua.php',
  filename: '/home/forge/application/vendor/nesbot/carbon/src/Carbon/Lang/dua.php'
}

@frankwallis
Copy link

The issue can be seen by installing this tool on Linux: https://github.com/mikesart/inotify-info

Running vite build with the Vanilla Extract Vite Plugin configured will cause file watchers to be created:
image

Removing the Vanilla Extract Vite Plugin from the configuration means the file watchers do not get created.

@askoufis
Copy link
Contributor

askoufis commented Mar 17, 2025

The issue can be seen by installing this tool on Linux: https://github.com/mikesart/inotify-info

Running vite build with the Vanilla Extract Vite Plugin configured will cause file watchers to be created: image

Removing the Vanilla Extract Vite Plugin from the configuration means the file watchers do not get created.

Thanks for sharing this tool, it definitely shows that vite build results in some files being watched. Indeed, setting watch: null does prevent this from happening, but it also breaks Vanilla Extract's HMR. Specifically, we use the file watcher to invalidate modules when they change:

server.watcher.on('change', (filePath) => {
runner.moduleCache.invalidateDepTree([filePath]);
});

However, after looking at a PR in React Router where they turned off their file watcher, maybe we could use the existing vite dev server's file watcher to invalidate the vite node runner's module cache, and then disable the vite node server's watcher. I'll test this out when I get a chance.

@frankwallis
Copy link

Agree there ought to be a long term fix to add files to the existing vite watcher instead of creating a new vite server.

In the short term setting the watch to null only when in vite build mode and setting it in Dec mode should work?

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

Successfully merging this pull request may close these issues.

4 participants