nwjs/nw.js · error · TypeError
Invalid MenuItem type: {option.type}
Error message
Invalid MenuItem type: {option.type} What it means
Thrown by the nw.MenuItem constructor when option.type is set to a value other than 'normal', 'checkbox', or 'separator'. If type is omitted it defaults to 'normal'; an explicit invalid value is rejected.
Source
Thrown at src/resources/api_nw_menuitem.js:32
try{obj.emit('click')}catch(e){console.error(e)}
});
function MenuItem(option) {
if (!(this instanceof MenuItem)) {
return new MenuItem(option);
}
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);
elseView on GitHub (pinned to e15da848e9)
Solutions
- Use one of 'normal', 'checkbox', 'separator' (lowercase).
- Omit type to default to 'normal'.
- For radio-like behavior, use 'checkbox' and manage mutually-exclusive checked state yourself.
Example fix
// before
new nw.MenuItem({ type: 'radio', label: 'Opt' });
// after
new nw.MenuItem({ type: 'checkbox', label: 'Opt' }); Defensive patterns
Strategy: validation
Validate before calling
const allowed = ['normal', 'checkbox', 'separator']; if (option.type && allowed.indexOf(option.type) === -1) option.type = 'normal';
Type guard
function isMenuItemType(v) { return ['normal', 'checkbox', 'separator'].indexOf(v) !== -1; } Try / catch
try { new nw.MenuItem(opt); } catch (e) { if (/Invalid MenuItem type/.test(e.message)) { opt.type = 'normal'; new nw.MenuItem(opt); } else throw e; } Prevention
- Lowercase and validate the type before construction.
- Note that 'radio' is not supported — use 'checkbox'.
When it happens
Trigger: Calling `new nw.MenuItem({ type: 'radio' })`, `new nw.MenuItem({ type: 'button' })`, or `new nw.MenuItem({ type: 'Normal' })` (case mismatch).
Common situations: Porting code from Electron (which supports 'radio'); typo; case sensitivity.
Related errors
- Invalid option.
- Invalid MenuItem type: {option.type}
- A normal MenuItem must have a label
- 'click' must be a valid Function
- Invalid menu type: {option.type}
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/763f298fc7ffa029.
Report an issue: GitHub.