Skip to content

AK0013

No provider found for injected context

What happened

You called inject() with a key, but no ancestor component called provide() with that same key. AkashJS walked up the component tree and found no matching provider.

How to fix

Either add a provide() call in an ancestor component, or supply a default/fallback value as the second argument to inject().

Example

ts
// Bad
const MyComponent = defineComponent(() => {
  const theme = inject("theme"); // no ancestor provides "theme"

  return () => h("div", {});
});

// Good — Option 1: Add a provider in an ancestor
const App = defineComponent(() => {
  provide("theme", { mode: "dark" });

  return () => h(MyComponent, {});
});

// Good — Option 2: Supply a default value
const MyComponent = defineComponent(() => {
  const theme = inject("theme", { mode: "light" });

  return () => h("div", { class: theme.mode });
});

Released under the MIT License.