appsmithorg/appsmith · error · Error

eventName should be a string

Error message

eventName should be a string

What it means

Thrown by window.appsmith.triggerEvent() in a legacy Custom Widget iframe. triggerEvent forwards a named event (with optional context) to the parent Appsmith app so an event handler can be bound on the widget. eventName must be a string because it is used as the event key in the CUSTOM_WIDGET_TRIGGER_EVENT message payload.

Source

Thrown at app/client/src/widgets/CustomWidget/component/customWidgetscript.js:272

            }
          };
        },
        updateModel: (obj) => {
          if (!obj || typeof obj !== "object") {
            throw new Error("updateModel expects an object as parameter");
          }

          appsmith.model = Object.assign(
            Object.assign({}, appsmith.model),
            obj,
          );

          // Send an update model message to the parent
          channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);
        },
        triggerEvent: (eventName, contextObj) => {
          if (typeof eventName !== "string") {
            throw new Error("eventName should be a string");
          } else if (contextObj && typeof contextObj !== "object") {
            throw new Error("contextObj should be an object");
          }

          // Send a trigger event message to the parent
          channel.postMessage(EVENTS.CUSTOM_WIDGET_TRIGGER_EVENT, {
            eventName,
            contextObj,
          });
        },
        model: {},
        ui: {},
        onReady: (fn) => {
          if (typeof fn !== "function") {
            throw new Error("onReady expects a function as parameter");
          }

          onReady = fn;

View on GitHub (pinned to 8cd9021c24)

Solutions

  1. Pass a string literal event name: appsmith.triggerEvent('onItemClick').
  2. Coerce known-safe identifiers: appsmith.triggerEvent(String(eventType)).
  3. Define a const enum/set of allowed event names and reference only those.
  4. Bind the corresponding event handler on the Custom Widget in the Appsmith app so the triggered event has a listener.

Example fix

// before
appsmith.triggerEvent(event); // event is an object { type: 'click' }

// after
appsmith.triggerEvent(event.type, event.payload);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof eventName !== 'string' || eventName.length === 0) {
  throw new TypeError('triggerEvent eventName must be a non-empty string');
}
appsmith.triggerEvent(eventName, context);

Type guard

const isEventName = (v) => typeof v === 'string' && v.trim().length > 0;

// usage
if (isEventName(name)) appsmith.triggerEvent(name, detail);

Try / catch

try {
  appsmith.triggerEvent(String(name), detail);
} catch (e) {
  console.error('triggerEvent rejected name:', e.message);
}

Prevention

When it happens

Trigger: Calling appsmith.triggerEvent(undefined), appsmith.triggerEvent(123), appsmith.triggerEvent({name:'click'}), or appsmith.triggerEvent() with no first argument. Passing a Symbol or any non-string identifier.

Common situations: Using a variable for the event name that was never assigned; sending a numeric code instead of a named event; destructuring an event object and passing the wrapper instead of the string field.

Related errors


AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12). Data as JSON: /api/errors/18fb2fbf504fd5b2. Report an issue: GitHub.