angular/angular-cli · error · Error
As of angular-devkit version 8.0, the "chokidar" package mus
Error message
As of angular-devkit version 8.0, the "chokidar" package must be installed in order to use watch() features.
What it means
The devkit's NodeJSAsyncHost/watch support uses chokidar's FSWatcher, which is treated as an optional peer dependency. loadFSWatcher tries require('chokidar'); if the require fails with MODULE_NOT_FOUND it throws this explanatory error telling you to install chokidar. (The odd message placement means any other require failure is rethrown as-is.) It exists because watch() features were moved to depend on an optional chokidar package in angular-devkit 8.0.
Source
Thrown at packages/angular_devkit/core/node/host.ts:47
await fsPromises.access(path, constants.F_OK);
return true;
} catch {
return false;
}
}
// This will only be initialized if the watch() method is called.
// Otherwise chokidar appears only in type positions, and shouldn't be referenced
// in the JavaScript output.
let FSWatcher: typeof import('chokidar').FSWatcher;
function loadFSWatcher() {
if (!FSWatcher) {
try {
FSWatcher = require('chokidar').FSWatcher;
} catch (e) {
if ((e as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
throw new Error(
'As of angular-devkit version 8.0, the "chokidar" package ' +
'must be installed in order to use watch() features.',
{
cause: e,
},
);
}
throw e;
}
}
}
/**
* An implementation of the Virtual FS using Node as the background. There are two versions; one
* synchronous and one asynchronous.
*/
export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
get capabilities(): virtualFs.HostCapabilities {View on GitHub (pinned to bb72145f9a)
Solutions
- Install chokidar: npm install chokidar (a version compatible with your devkit major version)
- If using pnpm/yarn PnP, add chokidar as an explicit dependency of the package using @angular-devkit/core
- Re-enable optional dependency installation (drop --omit=optional) and reinstall
Example fix
// before npm install @angular-devkit/core // after npm install @angular-devkit/core chokidar
Defensive patterns
Strategy: fallback
Validate before calling
let chokidarAvailable = false;
try { require.resolve('chokidar'); chokidarAvailable = true; } catch {}
if (!chokidarAvailable && needsWatch) {
throw new Error('watch() requires chokidar: npm install chokidar');
} Type guard
function hasChokidar(): boolean {
try { require.resolve('chokidar'); return true; } catch { return false; }
} Try / catch
try {
const watcher = host.watch(path, options);
// ...use watcher
} catch (e) {
if ((e as Error).message.includes('chokidar')) {
// fallback: polling with fs.watch / setInterval, or fail fast with install instructions
} else { throw e; }
} Prevention
- Explicitly list chokidar in package.json dependencies of any package using @angular-devkit/core watch
- Avoid npm install --omit=optional in environments that need watch features
- With pnpm, use public-hoist-pattern or direct dependency to make chokidar resolvable
- After devkit major upgrades, re-verify optional peer deps resolve from the consuming project
When it happens
Trigger: Calling watch() (or any API that watches the filesystem via the devkit node host) in a project where the chokidar package is not resolvable from node_modules.
Common situations: Upgrading angular-devkit from <8.0 where chokidar was bundled, pnpm/yarn strict dependency hoisting hiding chokidar, minimal installs (npm install --omit=optional) dropping chokidar, custom CLI tooling built on @angular-devkit/core without declaring chokidar.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- Unable to load message extractor. Please ensure '@angular/lo
- Tailwind CSS configuration file found (${relativeTailwindCon
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/f598ed099e8cd377.
Report an issue: GitHub.