nwjs/nw.js · error · TypeError

A normal MenuItem must have a label

Error message

A normal MenuItem must have a label

What it means

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.

Source

Thrown at src/resources/api_nw_menuitem.js:39

  EventEmitter.apply(this);

  if (typeof option != 'object')
    throw new TypeError('Invalid option.');

  if (!option.hasOwnProperty('type'))
    option.type = 'normal';

  if (option.type != 'normal' &&
      option.type != 'checkbox' &&
      option.type != 'separator')
    throw new TypeError('Invalid MenuItem type: ' + option.type);

  if (option.type == 'normal' || option.type == 'checkbox') {
    if (option.type == 'checkbox')
      option.checked = Boolean(option.checked);

    if (!option.hasOwnProperty('label'))
      throw new TypeError('A normal MenuItem must have a label');
    else
      option.label = String(option.label);

    if (option.hasOwnProperty('icon')) {
      option.shadowIcon = String(option.icon);
      option.icon = nwNative.getAbsolutePath(option.icon);
    }

    if (option.hasOwnProperty('iconIsTemplate'))
      option.iconIsTemplate = Boolean(option.iconIsTemplate);
    else
      option.iconIsTemplate = true;

    if (option.hasOwnProperty('tooltip'))
      option.tooltip = String(option.tooltip);

    if (option.hasOwnProperty('enabled'))
      option.enabled = Boolean(option.enabled);

View on GitHub (pinned to e15da848e9)

Solutions

  1. Add a label: `new nw.MenuItem({ type: 'normal', label: 'Save', icon: 'save.png' })`.
  2. Use an empty string label if you truly want no visible text: `{ label: '' }`.
  3. Use type: 'separator' if you wanted a divider.

Example fix

// before
new nw.MenuItem({ type: 'normal', icon: 'save.png' });
// after
new nw.MenuItem({ type: 'normal', label: 'Save', icon: 'save.png' });
Defensive patterns

Strategy: validation

Validate before calling

if ((option.type === 'normal' || option.type === 'checkbox') && !option.hasOwnProperty('label')) option.label = '';

Type guard

function hasRequiredLabel(o) { return o.type === 'separator' || (typeof o.label !== 'undefined'); }

Try / catch

try { new nw.MenuItem(opt); } catch (e) { if (/label/.test(e.message)) { opt.label = ''; new nw.MenuItem(opt); } else throw e; }

Prevention

When it happens

Trigger: Calling `new nw.MenuItem({ type: 'normal' })`, `new nw.MenuItem({ type: 'checkbox', checked: true })`, or passing only an icon with no label.

Common situations: 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.

Related errors


AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13). Data as JSON: /api/errors/4af898e0e77312b6. Report an issue: GitHub.