{"record":{"id":"4af898e0e77312b6","repo":"nwjs/nw.js","slug":"a-normal-menuitem-must-have-a-label-4af898","errorCode":null,"errorMessage":"A normal MenuItem must have a label","messagePattern":"A normal MenuItem must have a label","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_menuitem.js","lineNumber":39,"sourceCode":"  EventEmitter.apply(this);\n\n  if (typeof option != 'object')\n    throw new TypeError('Invalid option.');\n\n  if (!option.hasOwnProperty('type'))\n    option.type = 'normal';\n\n  if (option.type != 'normal' &&\n      option.type != 'checkbox' &&\n      option.type != 'separator')\n    throw new TypeError('Invalid MenuItem type: ' + option.type);\n\n  if (option.type == 'normal' || option.type == 'checkbox') {\n    if (option.type == 'checkbox')\n      option.checked = Boolean(option.checked);\n\n    if (!option.hasOwnProperty('label'))\n      throw new TypeError('A normal MenuItem must have a label');\n    else\n      option.label = String(option.label);\n\n    if (option.hasOwnProperty('icon')) {\n      option.shadowIcon = String(option.icon);\n      option.icon = nwNative.getAbsolutePath(option.icon);\n    }\n\n    if (option.hasOwnProperty('iconIsTemplate'))\n      option.iconIsTemplate = Boolean(option.iconIsTemplate);\n    else\n      option.iconIsTemplate = true;\n\n    if (option.hasOwnProperty('tooltip'))\n      option.tooltip = String(option.tooltip);\n\n    if (option.hasOwnProperty('enabled'))\n      option.enabled = Boolean(option.enabled);","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_menuitem.js#L21-L57","documentation":"Thrown by the nw.MenuItem constructor when type is 'normal' or 'checkbox' but no 'label' property is provided. Separator items do not need a label; all other item kinds must display text.","triggerScenarios":"Calling `new nw.MenuItem({ type: 'normal' })`, `new nw.MenuItem({ type: 'checkbox', checked: true })`, or passing only an icon with no label.","commonSituations":"Building an icon-only item (nw requires a label even when an icon is present); conditionally assigning label in a branch that did not run.","solutions":["Add a label: `new nw.MenuItem({ type: 'normal', label: 'Save', icon: 'save.png' })`.","Use an empty string label if you truly want no visible text: `{ label: '' }`.","Use type: 'separator' if you wanted a divider."],"exampleFix":"// before\nnew nw.MenuItem({ type: 'normal', icon: 'save.png' });\n// after\nnew nw.MenuItem({ type: 'normal', label: 'Save', icon: 'save.png' });","handlingStrategy":"validation","validationCode":"if ((option.type === 'normal' || option.type === 'checkbox') && !option.hasOwnProperty('label')) option.label = '';","typeGuard":"function hasRequiredLabel(o) { return o.type === 'separator' || (typeof o.label !== 'undefined'); }","tryCatchPattern":"try { new nw.MenuItem(opt); } catch (e) { if (/label/.test(e.message)) { opt.label = ''; new nw.MenuItem(opt); } else throw e; }","preventionTips":["Always include label for normal/checkbox items.","Use type: 'separator' for dividers."],"tags":["menuitem","constructor","required-field","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}