Build Error: "EMFILE: too many open files"

When running npm run build, I get the following error: “EMFILE: too many open files”

> project@0.1.0 build
> next build

  ▲ Next.js 14.2.35
  - Environments: .env.local

   Skipping linting
 ✓ Checking validity of types
   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Collecting page data
 ✓ Generating static pages (9/9)
Error: EMFILE: too many open files, open 'C:\Code\project-node\project_next\node_modules\intl-messageformat\src\error.js'
    at async open (node:internal/fs/promises:641:25)
    at async Object.readFile (node:internal/fs/promises:1245:14)
    at async Job.readFile (C:\Code\project-node\project_next\node_modules\next\dist\build\collect-build-traces.js:331:32)
    at async Job.emitDependency (C:\Code\project-node\project_next\node_modules\next\dist\compiled\@vercel\nft\index.js:1:40028)
    at async Job.maybeEmitDep (C:\Code\project-node\project_next\node_modules\next\dist\compiled\@vercel\nft\index.js:1:37013)
    at async Promise.all (index 2)
    at async Job.emitDependency (C:\Code\project-node\project_next\node_modules\next\dist\compiled\@vercel\nft\index.js:1:40278)
    at async Job.maybeEmitDep (C:\Code\project-node\project_next\node_modules\next\dist\compiled\@vercel\nft\index.js:1:37013)
    at async Promise.all (index 0)
    at async Job.emitDependency (C:\Code\project-node\project_next\node_modules\next\dist\compiled\@vercel\nft\index.js:1:40278) {
  errno: -4066,
  code: 'EMFILE',
  syscall: 'open',
  path: 'C:\\Code\\project-node\\project_next\\node_modules\\intl-messageformat\\src\\error.js'
}

I’m running Node 22.21.1 on Windows 11, and Plasmic installs Next.JS 14.2.35 on project create. I’m a bit hesitant to run using WSL, since the final product runs on Windows. I can’t disable file output tracing if I want to use the output: ‘standlone’ option.

This is a known issue with NextJS:

Here are the things I have tried to no avail:

  1. Experimental: Turbotrace
  2. Experimental: Excluded certain files.
  3. Ran setx NODE_OPTIONS "--max-old-space-size=4096" in Powershell before the build.
  4. Ignore lint during builds.

Here is the current next.config.mjs file:

/** @type {import('next').NextConfig} */
const nextConfig = {
  eslint: { ignoreDuringBuilds: true },
  trailingSlash: true,
  reactStrictMode: false,
  staticPageGenerationTimeout: 600,
  output: 'standalone',
};

export default nextConfig;

The ultimate goal is to have a small, portable build to install client side. I know most Plasmic apps are server-side, but due to our IT infrastructure, I have to run the app locally.

How can I do this?

I ran SET UV_THREADPOOL_SIZE=1 in cmd before running npm run build and walked away from my PC. It sort of worked when I came back. npm run start worked, but node .next\standalone\server.js didn’t work quite right. I had to…

  1. Copy in a custom installed module argon2, because its prebuilds were missing. (Used this for custom auth password hashing/checking.)
  2. Copy the .next\static folder to the .next\standalone\.next folder.
  3. Copy the public folder to the .next\standalone folder.

After that, I think everything works fine.

It will be difficult for us to debug your specific setup, but in any case there is probably not much that can be done besides what you’ve already tried. I see lots of questions about this online, but no perfect solutions, e.g. Raise the maximum open files limit on Windows · Issue #44832 · nodejs/node · GitHub

Some things that could possibly help:

  • Upgrade Node/Next (maybe node 24 + next 16 will be better? hard to say).
  • Avoid deps that might build from source (I’m not sure what’s pulling in argon2, maybe you can avoid it).
  • Increase file descriptor limit somehow. I don’t know how to do this in Windows, but running the build with elevated permissions might help.

Hi Samuel! Thank you for responding.

  1. As for upgrading, I hadn’t considered that. Not sure what would break, since Plasmic installs next 14. If I run into this snag again, I’ll give it a shot.
  2. As for avoiding those deps, I have updated my original post with a little more detail, not knowing you had replied. In it, I mentioned why I use argon2: one of my custom registered functions uses it to do custom hash/checking of passwords for plasmic custom auth. Not sure how to tell Plasmic or Next to install it.
  3. I’m not sure how to increase the limit, either. My approach was to linearize the build process rather than open up the allowable parallel processes.

All in all, my app folder is under 40MB now. The total portable build including portable Node, MsABON, and Node-RED ended up being under 400MB - not great, but okay. Zipped, it was 90MB which is reasonable enough for what I need.