Meituan-Dianping/mpvue · error

Injection "${key}" not found

Error message

Injection "${key}" not found

What it means

Raised by resolveInject after it walks the entire ancestor chain (via source.$parent) without finding the requested provideKey in any ancestor's _provided store. The inject entry resolved to no provider: either no ancestor declares a matching provide key, the provide/inject key strings mismatch (provide uses a different key name than inject requests), or the providing component is not actually an ancestor of the injecting one.

Source

Thrown at src/core/instance/inject.js:60

    // inject is :any because flow is not smart enough to figure out cached
    const result = Object.create(null)
    const keys = hasSymbol
        ? Reflect.ownKeys(inject)
        : Object.keys(inject)

    for (let i = 0; i < keys.length; i++) {
      const key = keys[i]
      const provideKey = inject[key]
      let source = vm
      while (source) {
        if (source._provided && provideKey in source._provided) {
          result[key] = source._provided[provideKey]
          break
        }
        source = source.$parent
      }
      if (process.env.NODE_ENV !== 'production' && !hasOwn(result, key)) {
        warn(`Injection "${key}" not found`, vm)
      }
    }
    return result
  }
}

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Add a provide entry in an ancestor component whose key matches the inject key exactly (or fix the key name mismatch between provide and inject)
  2. If the injection is genuinely optional, use the object syntax with a default: inject: { foo: { default: () => ({}) } }
  3. Verify the providing component is actually rendered as an ancestor in the component tree, not a sibling or child
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/core/instance/inject.js:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02). Data as JSON: /api/errors/340dd927b4a66134. Report an issue: GitHub.