Watch mode broken in 2.7.0 — chokidar 4 silently ignores glob patterns

Author: wernerglinkaCreated Mar 6, 2026Updated Jun 5, 2026
Labelstype:bug

Summary

Metalsmith 2.7.0's watch mode silently fails to detect file changes when glob patterns are passed to .watch(). Downgrading to 2.6.3 resolves the issue completely.

Root Cause

Metalsmith 2.7.0 bundles chokidar 4.0.3, which dropped glob/anymatch support. However, Metalsmith's .watch() API still accepts and passes glob patterns to chokidar without expansion. Chokidar 4 silently ignores these patterns rather than throwing an error.

Reproduction

javascript
metalsmith
  .watch([
    'src/**/*',
    'lib/layouts/**/*',
    'lib/assets/**/*',
    'lib/data/**/*'
  ])

With Metalsmith 2.7.0, this results in chokidar watching zero source files (only literal paths like lib/assets/main.css get watched). Editing any file under src/ or lib/layouts/ does not trigger a rebuild.

Verification

Direct test with chokidar 4 confirms the problem:

javascript
const chokidar = require('metalsmith/node_modules/chokidar');

// Glob patterns — does NOT work (watches 2 entries)
chokidar.watch(['src/**/*'], { cwd: process.cwd(), ignoreInitial: true });

// Directory paths — works (watches 900+ entries)
chokidar.watch(['src'], { cwd: process.cwd(), ignoreInitial: true });

Additional Issue

When .clean(true) is set (the default), rebuilds in watch mode fail with ENOTEMPTY because Metalsmith tries to rmdir the build directory while Browser-Sync is serving from it:

Error: ENOTEMPTY: directory not empty, rmdir '.../build'

This didn't surface with 2.6.3/chokidar 3 because the rebuild timing was different.

Environment

  • Metalsmith 2.7.0
  • chokidar 4.0.3 (bundled with Metalsmith 2.7.0)
  • Node.js v20.19.4
  • macOS (Darwin 25.3.0)

Expected Behavior

Either:

  1. Metalsmith should expand glob patterns into directory/file paths before passing them to chokidar 4, or
  2. Metalsmith should document that .watch() no longer accepts glob patterns in 2.7.0 and update the API to accept directory paths, or
  3. The negation pattern syntax (!path) should be mapped to chokidar's ignored option

Workaround

Pin Metalsmith to 2.6.3, which uses chokidar 3 with full glob support.