Skip to content

Injection symbol not found in imported component when running "vite dev" #6984

@bauer00

Description

@bauer00

Vue version

3.2.41

Link to minimal reproduction

https://github.com/bauer00/vue3-module-provide-test

Steps to reproduce

  1. Checkout https://github.com/bauer00/vue3-module-provide-test (It's a clean install with npm init vue@latest and only added Typescript)
  2. npm install (this should also install the module @test/module which is provided by a local package test-mdoule-0.0.1.tgz
  3. npm run dev
  4. Open browser

General description of what I try to do:

I have a plugin which on install() adds a value via provide to the app. Then I have a component which injects this value again and displays them. Both, the plugin and the component are in an imported module which is installed via npm. I also added both the plugin and the component directly into the app, to show that it only happens when I use the imported plugin and component.

What is expected?

Under Module Test Component it should output

Module inject: MODULE TEST

like it does under Local Test Component.

There should be no warning in the browser console.

What is actually happening?

The injection symbol can't be found and nothing is displayed in the imported component.

In the browser console this warning is visible:

[Vue warn]: injection "Symbol(module provide test)" not found. 
  at <ModuleTestComponent> 
  at <App>

Using the exact same injection symbol in a local component correctly injects the value.

System Info

No response

Any additional comments?

  • The imported module is not pre-built in any way, it just contains the source code. The project which imports the module should be in charge of building and bundling everything.
  • It works correct when building the project and running it.
  • It also works when I exclude the imported module in optimizeDeps, but I'm not sure if that's the expected behavior. (I've commented this in the provided vite.config.ts, so you can test it by just uncommenting this)
  • I've also done a quick test without typescript and without an injection key, just a normal string and it also seems to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions