About `Missing ref owner contextMissing ref owner context`

See original GitHub issue

Version

3.1.1

Reproduction link

https://github.com/qmhc/vue-test

我在项目里定义了一个 Test 组件,这个组件有一定程度的 ref 嵌套引用:

<!-- Test.vue -->
<template>
  <Test2 ref="select" class="test" @on-toggle="click">
    <template #control>
      <input :value="currentValue" />
    </template>
    <slot>
      <Test4 ref="test4" class="test-tel"></Test4>
    </slot>
  </Test2>
</template>

<!-- Test2.vue -->
<template>
  <div ref="wrapper" class="test2">
    <div ref="reference">
      <slot name="control">
        <Test4></Test4>
      </slot>
    </div>
  </div>
</template>

如果我直接在该项目中使用该组件,并不会产生任何问题,打包后应用可以正常使用;

当我将 Test 组件单独打包成插件后,在另一个项目安装并使用时:

在开发服务下会抛出警告: [Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render function.

打包后会直接抛出错误:Uncaught TypeError: Cannot read property 'refs' of null

Steps to reproduce

在原始的项目里,运行 yarn run dev 能正常使用。

运行 yarn run build 打包 Test 组件后,用 vite 的模版创建一个新的项目,link 引用原始项目打包的组件,随后运行 yarn run dev 后得到标题中的警告,在这个项目打包后,页面不能正常打开。

<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <!-- take warning -->
  <Test></Test>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { Test } from 'test'

export default defineComponent({
  name: 'App',
  components: {
    Test
  }
})
</script>

What is expected?

同样的组件,两个使用场景出现了差异

What is actually happening?

同样的组件,两个使用场景出现了差异

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
wuyongzhicommented, Aug 27, 2021

@qmhc 我刚刚解决了这个问题,我修改了两个地方。1.rollup.config 中增加 resolve: { dedupe: [‘vue’] } (这个是从vite,尤大回复别人的一个问题) 2.把vue从dependencies 改为 devDependencies 。不知道是哪个起作用了,但是确实解决了

我遇到了相同的问题,在 vite.config.ts 中增加 resolve: { dedupe: ['vue'] } 这个配置解决了,感谢!

2reactions
xsdreamcommented, Jul 7, 2021

@qmhc 我刚刚解决了这个问题,我修改了两个地方。1.rollup.config 中增加 resolve: { dedupe: [‘vue’] } (这个是从vite,尤大回复别人的一个问题) 2.把vue从dependencies 改为 devDependencies 。不知道是哪个起作用了,但是确实解决了

Read more comments on GitHub >

github_iconTop Results From Across the Web

About Missing ref owner contextMissing ref owner context #3930
[Vue warn]: Missing ref owner context. ref cannot be used on hoisted vnodes. A vnode with ref must be created inside the render...
Read more >
python - Scripting -- Can't figure out how to use correct contexts?
Anyways! I'm approaching this by creating an empty at the root of any selected curve, putting a "follow path" constraint on the empty,...
Read more >
aws-xray-sdk-core | Yarn - Package Manager
The AWS X-Ray SDK (the SDK) allows developers to instrument their web applications to automatically record information for incoming and outgoing requests and ......
Read more >
Configure Global Recorder — aws-xray-sdk 2.10.0 ...
Context Missing Strategy¶. Defines the recorder behavior when your instrumented code attempts to record data when no segment is open. Configure like the ......
Read more >
Troubleshoot mapping data flows - Azure Data Factory
Cause: One lookup field with more than one alternate key reference is not valid. Recommendation: Check your schema mapping and confirm that each ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found