Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot destructure property 'element' of 'undefined' as it is undefined #122

Closed
dylanmcgowan opened this issue Feb 9, 2022 · 4 comments

Comments

@dylanmcgowan
Copy link

Hello, I am trying to upgrade to Vue 3, and am running into an error preventing me from displaying the draggable items. Here is the full output: It's saying the scoped slot props are undefined if I'm not mistaken? Whats going on here?

TypeError: Cannot destructure property 'element' of 'undefined' as it is undefined.
    at http://test.localhost:3000/src/pages/questions.vue?import&t=1644426545158:231:37
    at renderFnWithContext (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:1753:17)
    at Object.get (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:9302:24)
    at computeNodes (http://test.localhost:3000/node_modules/.vite/vuedraggable.js?v=55c95ff4:5931:31)
    at computeComponentStructure (http://test.localhost:3000/node_modules/.vite/vuedraggable.js?v=55c95ff4:5967:25)
    at Proxy.render (http://test.localhost:3000/node_modules/.vite/vuedraggable.js?v=55c95ff4:6054:42)
    at Proxy.compatRender (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:5787:22)
    at renderComponentRoot (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:1785:39)
    at ReactiveEffect.componentUpdateFn [as fn] (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:5154:26)
    at ReactiveEffect.run (http://test.localhost:3000/node_modules/.vite/chunk-JWMJ27G5.js?v=55c95ff4:8268:23)

Here are the relevant packages:

{
  "@vue/compat": "^3.2.29",
  "@vue/compiler-sfc": "^3.2.29",
  "vue":  "^3.2.29",
  "vuedraggable": "^4.1.0"
}

This is how I'm using the <draggable> component in <template>..

<draggable
  v-model="dragItems"
  @update="handleDrop"
  handle=".my__drag"
  class="flex flex-col py-6 -mt-3 smd:mt-0"
  item-key="myId"
  :disabled="myDragDisabled"
>
  <template #item="{ element }">
    <my-item :stuff="element"  />
  </template>
</draggable>

This is how I'm importing it in <script>.. and I'm also using the new setup() function

<script>
import draggable from 'vuedraggable'
import { useStore, computed } from 'vuex'

export default {
  components: {
    draggable,
  },
  setup() {
    const store = useStore()
    const dragItems = computed(() => store.state.dragItems)

    return { dragItems }
  }
}
</script>

Any help would be very much appreciated!

@dylanmcgowan
Copy link
Author

Hey all, this issue went away after uninstalling @vue/compat

If you run into this issue when migrating your Vue 2 app to Vue 3, you'll unfortunately have to wait until you are at a place where you can uninstall the compatibility build. So comment your draggable shit out, get rid of the rest of the vue warnings, uninstall compat, then update to the new vue 3 draggable syntax from this repo.

@icodepixels
Copy link

Adding draggable.compatConfig = { MODE: 3 }; to the component should fix this issue.

@Sammuel09
Copy link

Sammuel09 commented Oct 13, 2023

Adding draggable.compatConfig = { MODE: 3 }; to the component should fix this issue.

@icodepixels, I'm curious, do you mean adding this config to the component in which the draggable component is used?

@davidphamntq
Copy link

@Sammuel09 yes

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

No branches or pull requests

4 participants