jestjs/jest · error · Error
notify reporter requires optional peer dependency "node-noti
Error message
notify reporter requires optional peer dependency "node-notifier" but it was not found
What it means
Thrown by loadNotifier() in NotifyReporter when the 'node-notifier' module cannot be required (require throws MODULE_NOT_FOUND). node-notifier is an OPTIONAL peer dependency of jest-reporters — it is only needed for the desktop-notification (notify) feature. When the user enables --notify or notify:true in config, NotifyReporter is constructed eagerly at class-load time, so the constructor's loadNotifier runs and rethrows the helpful message if the package isn't installed.
Source
Thrown at packages/jest-reporters/src/NotifyReporter.ts:166
title,
});
}
}
this._context.previousSuccess = success;
this._context.firstRun = false;
}
}
function loadNotifier(): typeof import('node-notifier') {
try {
return require('node-notifier');
} catch (error: any) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error;
}
throw new Error(
'notify reporter requires optional peer dependency "node-notifier" but it was not found',
);
}
}
View on GitHub (pinned to f49721c78e)
Solutions
- Install the optional peer dependency: npm install --save-dev node-notifier (or yarn/pnpm equivalent).
- If you don't need desktop notifications, remove --notify from CLI args or set notify: false in jest config.
- Ensure the install is recorded in package.json so CI/teammates get it too.
Example fix
// before: jest --notify -> error // after: install the dep // npm install --save-dev node-notifier // then jest --notify works
Defensive patterns
Strategy: validation
Validate before calling
// Before enabling --notify, ensure node-notifier is installed
function hasNodeNotifier(): boolean {
try { require.resolve('node-notifier'); return true; }
catch { return false; }
}
if (process.env.JEST_NOTIFY === '1' && !hasNodeNotifier()) {
console.warn('notify requested but node-notifier is missing; run: npm i -D node-notifier');
} else {
// safe to enable notify
} Try / catch
// Wrap the reporter setup so a missing optional dep doesn't crash the whole run
try {
NotifyReporter;
} catch (err: any) {
if (/node-notifier/.test(err?.message ?? '')) {
console.warn('Disabling notify: node-notifier not installed');
// drop NotifyReporter from the reporters list
} else {
throw err;
}
} Prevention
- Add node-notifier to package.json devDependencies whenever you enable notify.
- Don't enable --notify in CI where desktop notifications are meaningless.
- Document the optional dep in your project README so new contributors install it.
When it happens
Trigger: Running jest with --notify (CLI) or notify: true in jest config without having installed node-notifier; adding NotifyReporter to the reporters array without the dependency. The require('node-notifier') call inside loadNotifier throws MODULE_NOT_FOUND, which is caught and rethrown as this friendly Error.
Common situations: CI or fresh clone where node-notifier was never added to package.json; team enables notify locally for macOS notifications but forgets to declare the dep; upgrading jest and the notify feature was newly enabled by a teammate's config.
Related errors
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/63c8f7afeb4fe04b.json.
Report an issue: GitHub.