Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

webpack-dev-server runs, but saving a file does not rebuild or reload

ErrorNothing rebuilds after saving a file

Short answer

Watching fails when the operating system does not send file events (Docker, VirtualBox, WSL, network drives), when Linux runs out of inotify watchers, when the editor saves in a way that hides the change, or when the changed file sits outside the module graph and static folder. Turn on polling first, then check the others.

  • Applies to webpack 5, webpack-dev-server 5, Node.js 22, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run webpack in watch mode with progress output and save a file. Progress lines on save mean webpack sees the change and the problem is in your config; no output means the file events never arrive.

    npx webpack --watch --progress
  2. 2Match what you see, then jump to its fix

    1. 1Saves are ignored only inside Docker, VirtualBox, WSL or on an NFS share; the same project watches fine on the host.The project is in a container, VM or network folderFix
    2. 2A Not Enough Watchers message, or watching works for a small project and stops on a big one.Linux has run out of file watchersFix
    3. 3Only some editors trigger a rebuild; saving from the terminal with touch does.The editor saves in a way the watcher cannot seeFix
    4. 4Changes to .php, .html or other server-rendered templates never reload the page, while JavaScript changes do.The changed file is not part of the bundle or the static folderFix

What does the error look like?

  • Nothing rebuilds after saving a file
  • Not Enough Watchers

Cause 1 of 4

The project is in a container, VM or network folder

1Check

The docs say polling may help with NFS and with machines in VirtualBox, WSL, containers or Docker.

cat /proc/1/cgroup | head -3

2Fix

Turn on polling and ignore node_modules so the extra CPU cost stays small.

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

3Verify

Save a source file and watch the rebuild start within about a second.

npx webpack --watch --progress

Confirmed by webpack.js.org

Did this fix it?

Cause 2 of 4

Linux has run out of file watchers

1Check

Read the current limit. The docs suggest raising it to 524288 when it is low.

cat /proc/sys/fs/inotify/max_user_watches

2Fix

Raise the limit and reload the sysctl settings.

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

3Verify

Read the value again and restart the dev server.

cat /proc/sys/fs/inotify/max_user_watches

Confirmed by webpack.js.org

Did this fix it?

Cause 3 of 4

The editor saves in a way the watcher cannot see

1Check

The docs list two cases. Vim with backupcopy set to auto can replace the file instead of writing it, and WebStorm's option to back up files before saving can hide the change.

touch src/index.js
# in Vim: :set backupcopy?

2Fix

In Vim run the setting below; in WebStorm turn off the back-up-before-saving option.

:set backupcopy=yes

3Verify

Edit and save a file in the editor and watch the terminal.

npx webpack --watch --progress

Confirmed by webpack.js.org

Did this fix it?

Cause 4 of 4

The changed file is not part of the bundle or the static folder

1Check

The dev server watches files served from static.directory (public by default) and the webpack module graph. Anything else needs devServer.watchFiles.

grep -n -E "static|watchFiles" webpack.config.*

2Fix

List the extra globs to watch. Also make sure static.watch has not been set to false.

module.exports = {
  devServer: {
    watchFiles: ['src/**/*.php', 'public/**/*'],
  },
};

3Verify

Edit one of those files and confirm the page reloads.

npx webpack serve

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • In Docker and VM setups, put the polling options in the config from day one.
  • Ignore node_modules in watchOptions.
  • Keep the project on the Linux filesystem inside WSL, not on a mounted Windows drive, where it is possible.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.