vuejs/vuex · error · Error

[vuex] ${msg}

Error message

[vuex] ${msg}

What it means

assert is Vuex's internal assertion helper: any failed condition during store setup or API misuse throws with a '[vuex]' prefix. Callers use it to validate raw module options, state access under strict mode, action/mutation argument shape (unifyObjectStyle), etc.

Source

Thrown at src/util.js:65

}

/**
 * forEach for object
 */
export function forEachValue (obj, fn) {
  Object.keys(obj).forEach(key => fn(obj[key], key))
}

export function isObject (obj) {
  return obj !== null && typeof obj === 'object'
}

export function isPromise (val) {
  return val && typeof val.then === 'function'
}

export function assert (condition, msg) {
  if (!condition) throw new Error(`[vuex] ${msg}`)
}

export function partial (fn, arg) {
  return function () {
    return fn(arg)
  }
}

View on GitHub (pinned to bd907467b8)

Solutions

  1. Read the '[vuex] ...' message — it names the exact failed condition
  2. Ensure commit/dispatch are called as commit('type', payload) or commit({ type }, payload)
  3. Validate module option objects (state as function, namespaced boolean, etc.) before registerModule
  4. Check Vuex version compatibility of plugins

Example fix

// before
store.commit({}) // missing type -> assert fails
// after
store.commit({ type: 'increment' })
Defensive patterns

Strategy: validation

Validate before calling

function isValidCommitArg(arg) {
  return typeof arg === 'string' || (arg && typeof arg === 'object' && typeof arg.type === 'string' && arg.type.length > 0)
}
// call sites: if (!isValidCommitArg(t)) throw new TypeError('commit requires a type')

Type guard

function isCommitObject(v) {
  return typeof v === 'object' && v !== null && typeof v.type === 'string'
}

Try / catch

try {
  store.commit(payload)
} catch (e) {
  if (String(e.message).startsWith('[vuex]')) { console.error('Vuex API misuse:', e.message) }
  else throw e
}

Prevention

When it happens

Trigger: commit/dispatch called with an object lacking a valid 'type' (unifyObjectStyle assert); store state accessed before store finished construction; module registered with wrong 'rawModule' shape (assertRawModule); watch with invalid options; strict mode violations in enableStrictMode.

Common situations: Typo like commit({ type: 'increment' }) vs commit('increment'); passing a plain string where a function was expected; Vuex 3 vs Vuex 4 option mismatches; third-party plugins calling internal APIs incorrectly.

Related errors


AI-assisted analysis of vuejs/vuex@bd907467b8 (2026-08-28). Data as JSON: /api/errors/3e7e1091e5a285d4. Report an issue: GitHub.