Skip to content

inject() doesn't work in setup() when components are exported #6327

@fatbone008

Description

@fatbone008

Version

4.5.9

Reproduction link

[APP: git@github.com:fatbone008/vue3-test-demo.git Lib: git@github.com:fatbone008/vue3-test-lib.git](APP: git@github.com:fatbone008/vue3-test-demo.git Lib: git@github.com:fatbone008/vue3-test-lib.git)

APP: git@github.com:fatbone008/vue3-test-demo.git
Lib: git@github.com:fatbone008/vue3-test-lib.git

Environment info

System:
    OS: macOS 11.2
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    Yarn: 1.5.1 - /usr/local/bin/yarn
    npm: 7.5.6 - /usr/local/bin/npm
  Browsers:
    Chrome: 88.0.4324.192
    Edge: Not Found
    Firefox: 67.0.4
    Safari: 14.0.3
  npmPackages:
    @ant-design/icons-vue:  6.0.0 
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1 
    @vue/babel-helper-vue-transform-on:  1.0.2 
    @vue/babel-plugin-jsx:  1.0.2 
    @vue/babel-plugin-transform-vue-jsx:  1.2.1 
    @vue/babel-preset-app:  4.5.11 
    @vue/babel-preset-jsx:  1.2.4 
    @vue/babel-sugar-composition-api-inject-h:  1.2.1 
    @vue/babel-sugar-composition-api-render-instance:  1.2.4 
    @vue/babel-sugar-functional-vue:  1.2.2 
    @vue/babel-sugar-inject-h:  1.2.2 
    @vue/babel-sugar-v-model:  1.2.3 
    @vue/babel-sugar-v-on:  1.2.3 
    @vue/cli-overlay:  4.5.11 
    @vue/cli-plugin-babel: ^4.5.11 => 4.5.11 
    @vue/cli-plugin-eslint: ^4.5.11 => 4.5.11 
    @vue/cli-plugin-router:  4.5.11 
    @vue/cli-plugin-vuex:  4.5.11 
    @vue/cli-service: ^4.5.11 => 4.5.11 
    @vue/cli-shared-utils:  4.5.11 
    @vue/compiler-core:  3.0.5 
    @vue/compiler-dom:  3.0.5 
    @vue/compiler-sfc: ^3.0.5 => 3.0.5 
    @vue/compiler-ssr:  3.0.5 
    @vue/component-compiler-utils:  3.2.0 
    @vue/preload-webpack-plugin:  1.1.2 
    @vue/reactivity:  3.0.5 
    @vue/runtime-core:  3.0.5 
    @vue/runtime-dom:  3.0.5 
    @vue/shared:  3.0.5 
    @vue/web-component-wrapper:  1.2.0 
    ant-design-vue: ^2.0.0-rc.9 => 2.0.0-rc.9 
    eslint-plugin-vue: ^7.5.0 => 7.5.0 
    vue: ^3.0.5 => 3.0.5 
    vue-eslint-parser:  7.4.1 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.6 (16.1.2)
    vue-style-loader:  4.1.2 
    vue-template-es2015-compiler:  1.9.1 
    vue-types:  3.0.1 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

  1. In vue3-testing-lib, run lib command to build testing component lib.
  2. In vue3-testing-demo, run npm install path/to/lib, install testing lib above by file mode through npm, and import its component(Testing.vue) into Helloworld.vue as a component.
  3. npm run serve to start the demo project.
  4. check the lib component through vue-devtool, the provide is exist but injected variable is undefined. and there is warning in console: [Vue warn]: inject() can only be used inside setup() or functional components.

What is expected?

The inject variable in setup of lib component is available to detect provide correctly, rather than undefined, and there is no vue warning in console.

What is actually happening?

[Vue warn]: inject() can only be used inside setup() or functional components.
But inject() are not used in places other than in setup()

The customized lib component injected variable in setup function can not receive provide.
It seems that inject function can not get currentInstance when debugging in the vue source code.

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