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

Nuxt3 SSR Issue #96

Closed
itsmnthn opened this issue Oct 5, 2022 · 9 comments
Closed

Nuxt3 SSR Issue #96

itsmnthn opened this issue Oct 5, 2022 · 9 comments

Comments

@itsmnthn
Copy link

itsmnthn commented Oct 5, 2022

[Vue warn]: Failed to resolve directive: auto-animate
[nitro] [dev] [unhandledRejection] TypeError: Cannot read properties of undefined (reading 'getSSRProps')
   at component line where v-auto-animate is used
@pmcp
Copy link

pmcp commented Nov 2, 2022

I have the same issue, any insight into this? I tried wrapping my list in but still get an error in my console: "dir is undefined"

@itsmnthn
Copy link
Author

itsmnthn commented Nov 3, 2022

Nope i'm not able to solve this

@chris-visser
Copy link

I'm not getting the error on my current nuxt 3 stable. Maybe its resolved?

import { autoAnimatePlugin } from '@formkit/auto-animate/vue'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.use(autoAnimatePlugin)
})

@kllpff
Copy link

kllpff commented Mar 25, 2023

I have the same issue... need help :(

@justin-schroeder
Copy link
Member

Can someone produce a minimal reproduction and post it back to here? Happy to take a look

@MarkDonatelli
Copy link

I had the same issue with Nuxt 3 and updated my plugin the same as @chris-visser and it worked like a charm

@SuddenDev
Copy link

Okay, so I still experience the same problem, but maybe this is useful to someone.
The problem seems to be, that in the Vue Directive the getSSRProps() node is missing for nuxt to correctly work with the directive on the server side. A quick and dirty workaround from me:

// <your-nuxt-root>/plugins/auto-anim-directive.ts

import autoAnimate from "@formkit/auto-animate"

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.directive('auto-anim', {
    mounted: (el, binding) => {
      autoAnimate(el, binding.value || {});
    },
   // we can just return this as an empty object
    getSSRProps(binding, vnode) {
      return {}
    }
  })
})

Nuxt should import that directive automatically. Maybe restart your dev server.
In your Vue Component you can then use it as intended:

<script setup>
const toggle = ref(false);
</script>

<template>
  <!-- <ClientOnly> -->
    <div class="mb-20 m-container" v-auto-anim>
      <button class="p-5 bg-green" @click="toggle = !toggle">click me</button>
      <div class="bg-red w-20 h-20" v-if="toggle"></div>
    </div>
  <!-- </ClientOnly> -->
  </div>
</template>

@justin-schroeder: Maybe worth giving it a shot? If you want to, i can make a PR.

@ymansurozer
Copy link

Just in case someone wanders in here: Delete .client from your Nuxt 3 auto animate plugin, otherwise you get this error.

@Timothy1102
Copy link

Timothy1102 commented Oct 31, 2023

for anyone got this issue, check your module name in nuxt config file. it has to be @formkit/auto-animate/nuxt.

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@formkit/auto-animate/nuxt'],
})

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

9 participants