Skip to content

fix(inject): include key name in inject() warning when called outside setup#13368

Open
ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:fix/inject-warning-include-key
Open

fix(inject): include key name in inject() warning when called outside setup#13368
ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:fix/inject-warning-include-key

Conversation

@ifer47

@ifer47 ifer47 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • Include the injection key in the inject() warning message when it is called outside of setup() or functional components
  • Previously, the warning only said inject() can only be used inside setup() or functional components. with no indication of which key was being injected
  • Now includes (key: "keyName") in the warning, making it easy to identify which injection call is problematic

Problem

When using libraries like Nuxt UI that call inject() at the wrong time, developers see the warning but have no way to know which specific injection is causing the issue. This makes debugging difficult, especially in large applications with many inject calls.

Changes

Modified src/v3/apiInject.ts line 73 to include the key in the warning:

  • Before: inject() can only be used inside setup() or functional components.
  • After: inject() can only be used inside setup() or functional components. (key: "foo")

Closes #13287

🤖 Generated with Claude Code Best

… setup

When inject() is called outside of setup() or functional components,
the warning message now includes the injection key, making it easier
to identify which injection is causing the issue.

Closes vuejs#13287

Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve the warning in inject

1 participant