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
- Pass an actual function: introJs().onStart(function(element){ ... }).
- Log/inspect the argument type and fix the variable producing a non-function.
- Wire config-name strings to functions explicitly: const cbs = {start: fn, ...}.
- Use a fallback no-op when the callback is optional.
- 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
- Map string config names to functions explicitly in one place
- Never pass event-emitter or observer objects as callbacks
- Guard hot-reload code that reassigns handler variables
- Default optional callbacks to no-ops
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
- Provided callback for onhintsadded was not a function.
- Provided callback for onhintclick was not a function.
- Provided callback for onhintclose was not a function.
- Provided callback for onBeforeChange was not a function
- Provided callback for onChange was not a function.
AI-assisted analysis of usablica/intro.js@e5517e6a24 (2026-08-31).
Data as JSON: /api/errors/0e426182d9801c43.
Report an issue: GitHub.