{"record":{"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      {cause: error},\n    );\n  }\n}\n","sourceCodeStart":148,"sourceCodeEnd":172,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-reporters/src/NotifyReporter.ts#L148-L172","documentation":"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.","triggerScenarios":"Configuring the notify reporter (or setting notify: true in jest config) without having installed node-notifier in node_modules.","commonSituations":"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.","solutions":["Install the dependency: npm install --save-dev node-notifier (or yarn/pnpm/bun equivalent).","If you do not need desktop notifications, remove the notify reporter / set notify:false from your jest config.","On CI, disable notify entirely since desktop notifications are meaningless there."],"exampleFix":"// before\n// jest.config: reporters: [['<rootDir>/NotifyReporter', {notify: true}]]\n// after (option A)\n//   npm install --save-dev node-notifier\n// after (option B)\nmodule.exports = {notify: false};","handlingStrategy":"validation","validationCode":"try {\n  require.resolve('node-notifier');\n} catch {\n  throw new Error('Enable notify only after: npm install --save-dev node-notifier');\n}","typeGuard":"let canNotify = false;\ntry { require('node-notifier'); canNotify = true; } catch { canNotify = false; }","tryCatchPattern":null,"preventionTips":["Install node-notifier as a devDependency wherever notify is enabled.","Disable notify in CI/headless environments.","Document the optional peer dependency in your project README."],"tags":["reporter","dependency","notify","peer-dependency"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}