question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watchpack Error (watcher): Error: EMFILE: too many open files, watch

See original GitHub issue

Bug report

What is the current behavior?

Webpack watch doesn’t work when VSCode is running. Whenever I run webpack, it prints lots of messages like this:

Watchpack Error (watcher): Error: EMFILE: too many open files, watch <path>
Watchpack Error (watcher): Error: EMFILE: too many open files, watch <path>
Watchpack Error (watcher): Error: EMFILE: too many open files, watch <path>

If the current behavior is a bug, please provide the steps to reproduce.

I’m not sure how to reproduce it. The error is triggered if VSCode is running.

Here is the output:

asset index.js 94.2 KiB [compared for emit] (name: index)
orphan modules 15.9 KiB [orphan] 10 modules
runtime modules 972 bytes 5 modules
modules by path ./node_modules/ 28.9 KiB
  modules by path ./node_modules/@babel/runtime/helpers/esm/*.js 7.77 KiB 22 modules
  modules by path ./node_modules/style-loader/dist/runtime/*.js 5.75 KiB 6 modules
  modules by path ./node_modules/uuid/dist/esm-browser/*.js 3.24 KiB 5 modules
  modules by path ./node_modules/css-loader/dist/runtime/*.js 2.33 KiB 2 modules
  + 1 module
modules by path ./src/ 17.2 KiB
  modules by path ./src/components/ 3.31 KiB 3 modules
  modules by path ./src/*.ts 2.35 KiB 2 modules
  modules by path ./src/watchers/*.ts 6.02 KiB 2 modules
  modules by path ./src/models/*.ts 419 bytes 2 modules
  ./src/app.tsx 5.16 KiB [built] [code generated]
webpack 5.72.1 compiled successfully in 772 ms
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/watchers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/models'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/components'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/preact/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/preact'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers/esm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader/dist/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader/dist/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/projects/custom/mitm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/projects/custom'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/projects'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/babel-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/babel-loader/lib'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/sass-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/sass-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/path/to/project/src'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/path/to/project'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/projects/custom/mitm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/projects/custom'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/projects'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/components'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/models'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/watchers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/preact/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/projects/custom'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/babel-loader/lib'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/projects/custom/mitm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader/dist/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader/dist/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/sass-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/babel-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/preact'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/sass-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers/esm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/components'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/models'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/watchers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/babel-loader/lib'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/css-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/preact/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/sass-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/style-loader/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers/esm'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/components'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/models'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/watchers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/components'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/models'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/src/watchers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'
...

The last 5 lines are then being printed in an infinite loop:

Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'

Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist/esm-browser'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/uuid/dist'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime/helpers'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel/runtime'
Watchpack Error (watcher): Error: EMFILE: too many open files, watch '/path/to/project/node_modules/@babel'

My webpack.config.js:

const path = require("path");

module.exports = {
  mode: "development",
  entry: {
    index: path.resolve(__dirname, "src/index.ts"),
  },
  output: {
    path: path.resolve(__dirname, "build"),
    filename: "[name].js",
    clean: true,
    assetModuleFilename: "[name][ext]",
  },
  resolve: {
    extensions: [".js", ".jsx", ".ts", ".tsx"],
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              "@babel/preset-env",
              ["@babel/preset-typescript", { jsxPragma: "h" }],
            ],
            plugins: [
              "@babel/transform-runtime",
              ["@babel/plugin-transform-react-jsx", { pragma: "h" }],
            ],
          },
        },
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        use: ["style-loader", "css-loader", "sass-loader"],
      }
    ],
  },
  watch: true
};

What is the expected behavior?

No errors.

Other relevant information: System: Linux Kubuntu 20.04. VSCode: 1.66.2, 1.67.1 (tried both) Webpack: 5.72.1 Webpack-cli: 4.9.2 Babel: 7.17.10 Node.js: 16.14.0

$ awk '{print $1}' /proc/sys/fs/file-nr
22809
$ cat /proc/sys/fs/inotify/max_user_watches
531290

I also tried running VSCode w/o extensions: $ code --disable-extensions. It didn’t make any difference.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
OnkelTemcommented, May 26, 2022

I get this issue when running Angular’s ng serve. What is the workaround?

Not really. Just some vanilla js plus a little of Preact. My workaround was to restart the OS.

0reactions
php4fancommented, May 25, 2022

I get this issue when running Angular’s ng serve. What is the workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Watchpack Error (watcher): Error: EMFILE: too many open files ...
Hi,. Unfortunately, I had to do a system update four days ago and the problem is gone. I am closing the issue. Regards....
Read more >
Error: EMFILE: too many open files, watch '/' - Stack Overflow
It's been a system problem. After rebooting, it worked again as usual.
Read more >
How to fix the: "EMFILE: too many open files, watch" error in ...
A quick guide to how I solved a confusing React Native error. ... How to fix the: "EMFILE: too many open files, watch"...
Read more >
Error: EMFILE: too many open files, watch - Elixir Forum
This message gets displayed for every file in the assets directory, when starting the dev instance. If I stop other running programs, close ......
Read more >
Watchpack Error (watcher): Error: EMFILE: too many open files
I had a similar issue but without address after 'watch'. error screenshot. What I tried: increase ulimit; increase sysctl maxfile limit; install watchman ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found