nitro icon indicating copy to clipboard operation
nitro copied to clipboard

EMFILE: too many open files during build

Open PhotonQuantum opened this issue 7 months ago • 3 comments

Environment

[email protected] nodejs v22.14.0

Reproduction

See problem description. I think the problem itself is clear enough.

Describe the bug

https://github.com/nitrojs/nitro/blob/8c2a2d8589a1c65b091f8bce1ca25d756f25bb11/src/utils/compress.ts#L17 compressPublicAssets is opening all assets at the same time. https://github.com/nitrojs/nitro/pull/2458 solves a similar problem by limiting concurrency. I believe a similar approach can be used here to fix the issue.

Additional context

No response

Logs

02:37:44.039	⚙  Preparing app for cloudflare-module...
02:37:45.682	[error] EMFILE: too many open files, open '/opt/buildhome/repo/.output/public/_build/assets/ibm-plex-sans-latin-ext-700-italic-BKA4l2Ci.woff2'
02:37:45.683	  at async open (node:internal/fs/promises:638:25)
02:37:45.683	  at async Object.readFile (node:internal/fs/promises:1238:14)
02:37:45.683	  at async node_modules/.pnpm/[email protected][email protected]/node_modules/nitropack/dist/core/index.mjs:1690:28
02:37:45.683	  at async Promise.all (index 1001)
02:37:45.683	  at async compressPublicAssets (node_modules/.pnpm/[email protected][email protected]/node_modules/nitropack/dist/core/index.mjs:1683:3)
02:37:45.683	  at async copyPublicAssets (node_modules/.pnpm/[email protected][email protected]/node_modules/nitropack/dist/core/index.mjs:1922:5)
02:37:45.683	  at async createBuild (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]_sass@_mzhkbpwibqfcgna6zocrmkwzxy/node_modules/vinxi/lib/build.js:332:2)
02:37:45.683	  at async Object.run (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected][email protected]_sass@_mzhkbpwibqfcgna6zocrmkwzxy/node_modules/vinxi/bin/cli.mjs:245:5)
02:37:45.683	  at async runCommand (node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:316:16)
02:37:45.683	  at async runCommand (node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:307:11) 
02:37:45.683	
02:37:45.683	[error] EMFILE: too many open files, open '/opt/buildhome/repo/.output/public/_build/assets/ibm-plex-sans-latin-ext-700-italic-BKA4l2Ci.woff2'
02:37:45.711	 ELIFECYCLE  Command failed with exit code 1.
02:37:45.746	Failed: error occurred while running build command

PhotonQuantum avatar May 29 '25 06:05 PhotonQuantum

Thanks for the report. While in theory we can also add parallel limit for compression, i appreciate if you can provide a minimal reproduction.

pi0 avatar May 29 '25 09:05 pi0

I've created a reproduction for this: https://github.com/kricsleo/repro-nitro-3376 and a PR: https://github.com/nitrojs/nitro/pull/3384

kricsleo avatar Jun 02 '25 12:06 kricsleo

Also getting this error (while deploying to Cloudflare Workers). Is there a workaround?

mas-25 avatar Jun 28 '25 20:06 mas-25

Dove into it a bit more, and it seems to be related to packaging icons: https://github.com/cloudflare/workers-sdk/issues/9754

mas-25 avatar Jun 29 '25 05:06 mas-25