Skip to content

Error: EMFILE: too many open files, open.. #3164

Closed

Description

@McPo

I'm submitting a bug report

Webpack version:
1.10.x/2.x

Please tell us about your environment:
OSX 10.x / Linux / Windows 10

Current behavior:
Obtaining too many open files when using the copy-webpack-plugin.

Expected/desired behavior:
Not to reach the limit of open files and therefore have the build succeed.

@tallaxes suggested a fix which lies within Compiler.js. webpack/copy-webpack-plugin#59

require("async").forEach(Object.keys(compilation.assets), function(file, callback) {

to

require("async").forEachLimit(Object.keys(compilation.assets), 2000,
  require("async").ensureAsync(function(file, callback) {

One issue with this fix is the number is different per machine and depending on what else is running on the machine. One possible solution is to use an environment variable and fall back to a default value anyway.

require("async").forEachLimit(Object.keys(compilation.assets), process.env.WEBPACK_FILE_LIMIT || 100,
  require("async").ensureAsync(function(file, callback) {

There has also been mentions about using graceful-fs. However I had no luck when monkey patching it. This was the only thing that solved the issue for me. #250

  • Browser:
    Electron

Activity

  1. McPo commented on Oct 20, 2016

    @McPo
    Author

    Ive created a PR. for those suffering from this issue you can use it right away by setting your package.json to

    "webpack": "McPo/webpack#1.13.2-file-limit"

    Ive limited to 1000, but perhaps 500 is more reasonable.
    You can to set it to a user defined value using the environment variable WEBPACK_FILE_LIMIT

    #3166

  2. MagicDuck commented on Oct 20, 2016

    @MagicDuck
    Contributor

    We're encountering the exact same issue on our side.... I spent like a day messing with graceful-fs and happypack. In the end I had to disable happypack, but the error still appears, albeit less frequently than with happypack.

  3. webpack-bot commented on Aug 11, 2017

    @webpack-bot
    Contributor

    This issue had no activity for at least half a year.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  4. added
    status: stale
    on Aug 11, 2017
  5. added a commit that references this issue on Aug 11, 2017
    f9bf8a9
  6. dmichon-msft commented on Nov 20, 2017

    @dmichon-msft
    Contributor

    This still repros any time a loader adds a large number of assets to the compilation. The parallel modules work fine, but the asset emitting step crashes due to too many open file handles.

  7. webpack-bot commented on Apr 9, 2021

    @webpack-bot
    Contributor

    For maintainers only:

    • webpack-4
    • webpack-5
    • bug
    • critical-bug
    • enhancement
    • documentation
    • performance
    • dependencies
    • question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions