usablica/intro.js · error

Provided callback for onexit was not a function.

Error message

Provided callback for onexit was not a function.

What it means

Tour class onExit registers the callback fired when the tour is exited, stored in this.callbacks.exit. It throws this error when the argument is not a function, consistent with all intro.js callback setters.

Source

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

    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) {
    if (!isFunction(callback)) {
      throw new Error("Provided callback for onexit was not a function.");
    }

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

  /**
   * @deprecated onskip is deprecated, please use onSkip instead.
   */
  onskip(callback: introSkipCallback) {
    return this.onSkip(callback);
  }

  /**
   * Add a callback to be called when the tour is skipped
   * @param {Function} callback callback function to be called
   */
  onSkip(callback: introSkipCallback) {

View on GitHub (pinned to e5517e6a24)

Solutions

  1. Pass a function: introJs().onExit(function(){ ... }).
  2. Fix the undefined/non-function source (prop name, import, assignment order).
  3. Ensure registration happens before any code that clears the handler.
  4. Provide a default: introJs().onExit(cfg.onExit || (() => {})).
  5. Guard the registration with typeof === 'function'.

Example fix

// before
let cleanupCb;
// ... cleanupCb = null by the time setup runs
introJs().onExit(cleanupCb);
// after
introJs().onExit(function cleanup() { /* restore state */ });
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof exitCb === 'function') {
  introJs().onExit(exitCb);
} else {
  introJs().onExit(() => {});
}

Type guard

const isExitCb = (v: unknown): v is () => void => typeof v === 'function';

Try / catch

try {
  intro().onExit(cb);
} catch (e) {
  if (String(e.message).includes('onexit was not a function')) {
    intro().onExit(() => {});
  } else { throw e; }
}

Prevention

When it happens

Trigger: introJs().onExit() with no argument or any non-function value — commonly undefined from an incorrectly destructured prop or a cleanup function that was already called/removed.

Common situations: React/Vue unmount logic removing the handler variable before intro setup runs; passing window event wrapper results; mismatched casing (onexit vs onExit) referencing different wrappers.

Related errors


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