Budibase/budibase · error

gotoFunc must be a function, found a "${typeof gotoFunc}" in

Error message

gotoFunc must be a function, found a "${typeof gotoFunc}" instead

What it means

The navigation store is initialized with a SvelteKit-style goto function injected via init(gotoFunc). To fail fast on misconfiguration, init validates the argument is actually a function before storing it, throwing with the found typeof value otherwise.

Source

Thrown at packages/builder/src/stores/portal/navigation.ts:20

type GotoFuncType = (path: string) => void

interface NavigationState {
  initialisated: boolean
  goto: GotoFuncType
}

class NavigationStore extends BudiStore<NavigationState> {
  constructor() {
    super({
      initialisated: false,
      goto: undefined as any,
    })
  }

  init(gotoFunc: GotoFuncType) {
    if (typeof gotoFunc !== "function") {
      throw new Error(
        `gotoFunc must be a function, found a "${typeof gotoFunc}" instead`
      )
    }
    this.set({
      initialisated: true,
      goto: gotoFunc,
    })
  }
}

export const navigation = new NavigationStore()

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Pass the actual goto function, e.g. import { goto } from "@svelterouter/kit"-style source and call navigation.init(goto)
  2. Check the import — ensure it destructures the function, not the module
  3. Ensure init is called in the right lifecycle where goto is defined
  4. In tests, provide a jest.fn() mock as the gotoFunc

Example fix

// before
import * as nav from "$app/navigation"
navigation.init(nav)
// after
import { goto } from "$app/navigation"
navigation.init(goto)
Defensive patterns

Strategy: validation

Validate before calling

if (typeof goto !== "function") {
  throw new Error("navigation.init requires a goto function")
}
navigation.init(goto)

Type guard

const isGotoFunc = (f: unknown): f is GotoFuncType =>
  typeof f === "function"

Try / catch

try {
  navigation.init(goto)
} catch (e) {
  if (e.message.includes("gotoFunc must be a function")) {
    console.error("Check the goto import — expected the function, not the module")
  } else throw e
}

Prevention

When it happens

Trigger: Calling init() with undefined/null (forgetting to pass goto), or passing a non-function such as a string path, an object, or a wrongly-imported module instead of the goto function.

Common situations: Bad import of goto (importing the module namespace rather than the function); calling init before SvelteKit context is available; refactor renamed/moved goto and the call site wasn't updated; testing setup not providing a mock goto.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/1320c6de5d9deb9d. Report an issue: GitHub.