Categories
JavaScript Answers

How to fix webpack –watch isn’t compiling changed files with JavaScript?

Spread the love

Sometimes, we want to fix webpack –watch isn’t compiling changed files with JavaScript.

In this article, we’ll look at how to fix webpack –watch isn’t compiling changed files with JavaScript.

How to fix webpack –watch isn’t compiling changed files with JavaScript?

To fix webpack –watch isn’t compiling changed files with JavaScript, we can increase the number of watchers and ignore files that don’t have to be watched.

We run

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

to increase the number of watchers to 524288.

Also, in our Webpack config, we write

//...

module.exports = {
  //...
  watchOptions: {
    poll: true,
    ignored: /node_modules/,
  },
  //...
};

to ignore the /node_modules/ folder in the watch options so that Webpack doesn’t watch anything in the folder for changes.

Conclusion

To fix webpack –watch isn’t compiling changed files with JavaScript, we can increase the number of watchers and ignore files that don’t have to be watched.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *