jestjs/jest · error · Error

notify reporter requires optional peer dependency…

Error message

notify reporter requires optional peer dependency "node-notifier" but it was not found

What it means

Thrown by NotifyReporter's loadNotifier when require('node-notifier') fails with MODULE_NOT_FOUND. node-notifier is an optional peer dependency of jest-reporters used only by the notify reporter; if it is not installed, the reporter cannot function.

Solutions

  1. Install the dependency: npm install --save-dev node-notifier (or yarn/pnpm/bun equivalent).
  2. If you do not need desktop notifications, remove the notify reporter / set notify:false from your jest config.
  3. On CI, disable notify entirely since desktop notifications are meaningless there.

Example fix

// before
// jest.config: reporters: [['<rootDir>/NotifyReporter', {notify: true}]]
// after (option A)
//   npm install --save-dev node-notifier
// after (option B)
module.exports = {notify: false};
Defensive patterns

Strategy: validation

Validate before calling

try {
  require.resolve('node-notifier');
} catch {
  throw new Error('Enable notify only after: npm install --save-dev node-notifier');
}

Type guard

let canNotify = false;
try { require('node-notifier'); canNotify = true; } catch { canNotify = false; }

Prevention

When it happens

Trigger: Configuring the notify reporter (or setting notify: true in jest config) without having installed node-notifier in node_modules.

Common situations: Fresh clone without installing optional deps; a package manager that prunes optional peers; CI image lacking libnotify/dbus dependencies; enabling notify on a headless CI where notifications are unwanted anyway.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/63c8f7afeb4fe04b. Report an issue: GitHub.

Appendix: 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',
      {cause: error},
    );
  }
}

View on GitHub (pinned to 8e6d128e4a)