{"id":"63c8f7afeb4fe04b","repo":"jestjs/jest","slug":"notify-reporter-requires-optional-peer-dependency","errorCode":null,"errorMessage":"notify reporter requires optional peer dependency \"node-notifier\" but it was not found","messagePattern":"notify reporter requires optional peer dependency \"node-notifier\" but it was not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-reporters/src/NotifyReporter.ts","lineNumber":166,"sourceCode":"          title,\n        });\n      }\n    }\n\n    this._context.previousSuccess = success;\n    this._context.firstRun = false;\n  }\n}\n\nfunction loadNotifier(): typeof import('node-notifier') {\n  try {\n    return require('node-notifier');\n  } catch (error: any) {\n    if (error.code !== 'MODULE_NOT_FOUND') {\n      throw error;\n    }\n\n    throw new Error(\n      'notify reporter requires optional peer dependency \"node-notifier\" but it was not found',\n    );\n  }\n}\n","sourceCodeStart":148,"sourceCodeEnd":171,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-reporters/src/NotifyReporter.ts#L148-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: jest --notify  -> error\n// after: install the dep\n// npm install --save-dev node-notifier\n// then jest --notify works","handlingStrategy":"validation","validationCode":"// Before enabling --notify, ensure node-notifier is installed\nfunction hasNodeNotifier(): boolean {\n  try { require.resolve('node-notifier'); return true; }\n  catch { return false; }\n}\nif (process.env.JEST_NOTIFY === '1' && !hasNodeNotifier()) {\n  console.warn('notify requested but node-notifier is missing; run: npm i -D node-notifier');\n} else {\n  // safe to enable notify\n}","typeGuard":null,"tryCatchPattern":"// Wrap the reporter setup so a missing optional dep doesn't crash the whole run\ntry {\n  NotifyReporter;\n} catch (err: any) {\n  if (/node-notifier/.test(err?.message ?? '')) {\n    console.warn('Disabling notify: node-notifier not installed');\n    // drop NotifyReporter from the reporters list\n  } else {\n    throw err;\n  }\n}","preventionTips":["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."],"tags":["jest-reporters","notify","peer-dependency","missing-dependency"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}