usablica/intro.js · error

Provided callback for onstart was not a function.

Error message

Provided callback for onstart was not a function.

What it means

Tour class onStart registers the callback fired when the tour starts, stored in this.callbacks.start. It validates the argument with isFunction and throws this error otherwise, preventing a TypeError at tour start time.

Source

Thrown at src/packages/tour/tour.ts:602

    this.callbacks.complete = callback;
    return this;
  }

  /**
   * @deprecated onstart is deprecated, please use onStart instead.
   */
  onstart(callback: introStartCallback) {
    return this.onStart(callback);
  }

  /**
   * Add a callback to be called when the tour is started
   * @param {Function} callback callback function to be called
   */
  onStart(callback: introStartCallback) {
    if (!isFunction(callback)) {
      throw new Error("Provided callback for onstart was not a function.");
    }

    this.callbacks.start = callback;
    return this;
  }

  /**
   * @deprecated onexit is deprecated, please use onExit instead.
   */
  onexit(callback: introExitCallback) {
    return this.onExit(callback);
  }

  /**
   * Add a callback to be called when the tour is exited
   * @param {Function} callback callback function to be called
   */
  onExit(callback: introExitCallback) {

View on GitHub (pinned to e5517e6a24)

Solutions

  1. Pass an actual function: introJs().onStart(function(element){ ... }).
  2. Log/inspect the argument type and fix the variable producing a non-function.
  3. Wire config-name strings to functions explicitly: const cbs = {start: fn, ...}.
  4. Use a fallback no-op when the callback is optional.
  5. Catch the throw during setup to surface misconfiguration early.

Example fix

// before
const cbs = { onStart: 'startTour' };
introJs().onStart(cbs.onStart); // string
// after
introJs().onStart(cbs.startHandler); // function reference
Defensive patterns

Strategy: validation

Validate before calling

const startCb = cbs.onStart;
if (typeof startCb !== 'function') { throw new TypeError('onStart callback must be a function'); }
introJs().onStart(startCb);

Type guard

type IntroCb = (el?: Element) => void;
const isIntroCb = (v: unknown): v is IntroCb => typeof v === 'function';

Try / catch

try {
  tour.onStart(cb);
} catch (e) {
  if (e.message.includes('onstart was not a function')) {
    tour.onStart(() => {});
  } else { throw e; }
}

Prevention

When it happens

Trigger: introJs().onStart() or onStart(someNonFunction) — undefined from an unassigned variable, null, or an event-emitter object passed by mistake.

Common situations: Setting up tours from JSON-driven config where callbacks must be mapped by name in JS; hot-reload environments losing handler assignments; wrong method chaining order leaving a helper undefined.

Related errors


AI-assisted analysis of usablica/intro.js@e5517e6a24 (2026-08-31). Data as JSON: /api/errors/0e426182d9801c43. Report an issue: GitHub.