lucide: Vercel/Next.js/React/Node 'too many open files' error

Prerequisites

Step to reproduce

Installed using yarn, following https://github.com/lucide-icons/lucide/tree/main/packages/lucide-react#lucide-react.

Error happens when all icons are imported as React Component individually, and also when all icons are imported using Next.js dynamic import.

Actual behavior

Any message or error

Error message via Vercel logs:

[Error: EMFILE: too many open files, open '/var/task/node_modules/lucide-react/dist/esm/icons/share.mjs'] {
  errno: -24,
  code: 'EMFILE',
  syscall: 'open',
  path: '/var/task/node_modules/lucide-react/dist/esm/icons/share.mjs'
}
[Error: EMFILE: too many open files, open '/var/task/node_modules/lucide-react/dist/esm/icons/share.mjs'] {
  errno: -24,
  code: 'EMFILE',
  syscall: 'open',
  path: '/var/task/node_modules/lucide-react/dist/esm/icons/share.mjs',
  page: '/robots.txt'
}
RequestId: ace94785-66ac-47ca-81d7-ff1ab00793bc Error: Runtime exited without providing a reason
Runtime.ExitError

Client side, nothing to go on:

image

Resources

image

Update; perhaps related?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 18 (2 by maintainers)

Most upvoted comments

Confirmed downgrading to 0.261.0 fixed the issues for me as well.

Solved by adding the following to next.config.js:

// Modularize Lucide icon imports; otherwise, Vercel
// throws 'too many open files' error (https://github.com/lucide-icons/lucide/issues/1446)
// @see https://nextjs.org/docs/architecture/nextjs-compiler#using-named-imports
modularizeImports: {
  'lucide-react': {
    transform: 'lucide-react/{{member}}',
    skipDefaultConversion: true,
    preventFullImport: true,
  },
},

But there are some problems - could you guys cooperate to get this fixed on both sides? 😃 Would be cool.

I can confirm that 0.261.0 without ^ etc works fine with Next.js on Vercel

What next.config.js confiugration are you using? This one:

modularizeImports: {
  'lucide-react': {
    transform: 'lucide-react/{{member}}',
    skipDefaultConversion: true,
    preventFullImport: true,
  },
}

?

Asking as this is making the app fail locally:

Module not found: Can't resolve 'lucide-react/Check'
  1 | import { Check, ChevronRight, Circle } from "lucide-react";

There is honestly no way that this option would ever work. The files are in some deeply nested folder which are not specified in the package.json from the lucide-react package

Good news. NextJS PR just got merged to canary.

It works on Vercel, v0.261.0, no configuration added. But, like I mentioned in one comment, that can be just me being below the limit and the problem still being there, as locally I still compile 1000+ more components when the app is run.

Related/duplicate issue see #1457. See my comment in #1457 (possible todo with .mjs modules), for the time being try version: 0.261.0

Solved by adding the following to next.config.js:

// Modularize Lucide icon imports; otherwise, Vercel
// throws 'too many open files' error (https://github.com/lucide-icons/lucide/issues/1446)
// @see https://nextjs.org/docs/architecture/nextjs-compiler#using-named-imports
modularizeImports: {
  'lucide-react': {
    transform: 'lucide-react/{{member}}',
    skipDefaultConversion: true,
    preventFullImport: true,
  },
},

This is not working, checking locally, and getting:

Module not found: Package path ./Check is not exported from package /[path to project]/node_modules/lucide-react (see exports field in /[path to project]/node_modules/lucide-react/package.json)

I am on version 0.263.1