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

Regression: Remix CI build fails with ENOSPC #10324

Open
cmd-johnson opened this issue Dec 11, 2024 · 1 comment
Open

Regression: Remix CI build fails with ENOSPC #10324

cmd-johnson opened this issue Dec 11, 2024 · 1 comment

Comments

@cmd-johnson
Copy link
Contributor

Reproduction

  1. Use linux
  2. Use a freshly scaffolded remix app (npx create-remix)
    • right now, this uses remix 2.15.1, but the reproduction works starting from 2.14.0
  3. Decrease the inotify watch limit to some low value (e.g. sudo sysctl fs.inotify.max_user_watches=10000)
    • you can reset the limit to your system's default without rebooting by running sudo sysctl --system)
  4. run npm run build

System Info

System:
    OS: Linux 6.1 Manjaro Linux
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 38.54 GB / 62.55 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.11.0 - ~/.nvm/versions/node/v22.11.0/bin/node
    Yarn: 3.3.1 - ~/.nvm/versions/node/v22.11.0/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v22.11.0/bin/npm
    pnpm: 8.15.9 - ~/.nvm/versions/node/v22.11.0/bin/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Chromium: 131.0.6778.108
  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

The build doesn't fail, even with a low inotify watch limit.

This worked fine, up until remix 2.14.0. After digging a little deeper, it looks like this happens because the vite plugin now creates a dev server, even when doing a production build, and that server appears to watch basically everything in the project directory.

Going even deeper, it seems like the actual culprit is this:

  1. ViteNode.createContext is called with server: { watch: null }
  2. ViteNode.createContext calls vite.mergeConfig with its own server config and the viteConfig argument
  3. vite.mergeConfig explicitly doesn't merge null and undefined values into the base config (because null == undefined)
  4. The { server: { watch: null } } value never actually makes it to the vite.createServer call.

This means that there is currently no way to merge null or undefined values into the vite config using vite.mergeConfig, which is unfortunate, because both have pretty distinctive meanings inside server.watch.

I've opened an issue for this mergeConfig quirk over at the vite repository as well.

If they decide that this isn't a bug, but a feature, the watch config would have to manually be merged by remix.

Possibly related to #10250.

Actual Behavior

The build fails with the following output:

Error
> npm run build                                                                                                                                                                                                ✔  4s  

> build
> remix vite:build

node:internal/fs/watchers:247
    const error = new UVException({
                  ^

Error: ENOSPC: System limit for number of file watchers reached, watch '«project-directory»'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2468:36)
    at createFsWatchInstance (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42779:17)
    at setFsWatchListener (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42826:15)
    at NodeFsHandler._watchWithNodeFs (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:42981:14)
    at NodeFsHandler._handleDir (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43217:19)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at NodeFsHandler._addToNodeFs (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43267:16)
    at file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:44284:21
    at async Promise.all (index 0)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:44480:10)
    at NodeFsHandler._addToNodeFs (file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:43295:18)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at file://«project-directory»/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:44284:21
    at async Promise.all (index 0) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '«project-directory»',
  filename: '«project-directory»'
}

Node.js v22.11.0
@cmd-johnson
Copy link
Contributor Author

For now, this patch of @remix-run/dev fixes the issue for me:

diff --git a/dist/vite/vite-node.js b/dist/vite/vite-node.js
index f195820ed85726a7ba27b5e736db68506af10ab1..b42a6f51181741c06b5d1faa741bb34daba96157 100644
--- a/dist/vite/vite-node.js
+++ b/dist/vite/vite-node.js
@@ -23,7 +23,8 @@ async function createContext(viteConfig = {}) {
   let devServer = await vite.createServer(vite.mergeConfig({
     server: {
       preTransformRequests: false,
-      hmr: false
+      hmr: false,
+      ...viteConfig.server
     },
     optimizeDeps: {
       noDiscovery: true

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