nwjs/nw.js · error · TypeError
Must set 'title' or 'icon' field in option
Error message
Must set 'title' or 'icon' field in option
What it means
Thrown by the nw.Tray constructor when the options object has neither a 'title' nor an 'icon' property. A tray entry must show something — text or an icon — so providing an empty or unrelated options object is rejected.
Source
Thrown at src/api/tray/tray.js:28
//
// The above copyright notice and this permission notice shall be included in al
// l copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var v8_util = process.binding('v8_util');
function Tray(option) {
if (typeof option != 'object')
throw new TypeError('Invalid option');
if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon'))
throw new TypeError("Must set 'title' or 'icon' field in option");
if (!option.hasOwnProperty('title'))
option.title = '';
else
option.title = String(option.title);
if (option.hasOwnProperty('icon')) {
option.shadowIcon = String(option.icon);
option.icon = nw.getAbsolutePath(option.icon);
}
if (option.hasOwnProperty('alticon')) {
option.shadowAlticon = String(option.alticon);
option.alticon = nw.getAbsolutePath(option.alticon);
}
if (option.hasOwnProperty('iconsAreTemplates'))
option.iconsAreTemplates = Boolean(option.iconsAreTemplates);View on GitHub (pinned to e15da848e9)
Solutions
- Add at least one of title or icon: `new nw.Tray({ icon: 'icon.png' })`.
- If using an icon, ensure the path is a string and resolvable.
Example fix
// before
new nw.Tray({ tooltip: 'My App' });
// after
new nw.Tray({ title: 'My App', tooltip: 'My App' }); Defensive patterns
Strategy: validation
Validate before calling
if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon')) {
throw new Error('Tray requires title or icon');
} Type guard
function hasTitleOrIcon(o) { return o && (typeof o.title !== 'undefined' || typeof o.icon !== 'undefined'); } Try / catch
try { new nw.Tray(opt); } catch (e) { if (/title or icon/.test(e.message)) opt.title = 'App'; else throw e; } Prevention
- Make title or icon a required field in your tray config schema.
- Validate the option object shape before construction.
When it happens
Trigger: Calling `new nw.Tray({})`, `new nw.Tray({ tooltip: 'x' })`, or `new nw.Tray({ click: fn })` with no title/icon.
Common situations: Building the options object conditionally and both branches skipped; renaming the property to 'name' or 'text' instead of 'title'.
Related errors
- A normal MenuItem must have a label
- Shortcut requires 'key' to specify key combinations.
- Invalid option
- 'click' must be a valid Function
- 'menu' must be a valid Menu
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/5bef832baaf67cab.
Report an issue: GitHub.