nuxt: Velocity.js doesn't work as ssr: false plugin, how to use it?

I have a plugin

import Velocity from 'velocity-animate'

export {
  Velocity
}

Using it with ssr: false

Then import it in component as import Velocity from '~/plugins/velocity'

I got an error in console

[vue-router] Failed to resolve async component default: ReferenceError: window is not defined
[vue-router] uncaught error during route navigation:
ReferenceError: window is not defined

And in browser

Cannot read property 'options' of undefined
<div align="right">This question is available on Nuxt.js community (#c1800)</div>

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26

Most upvoted comments

We solved it on vue discord

Plugin code then simply use it in components, pages etc… this.$velocity

import Velocity from 'velocity-animate'

export default (ctx, inject) => {
  inject('velocity', Velocity)
}

@gianniskarmas it works because it doesn’t do anything. You just import it (in the plugin file). Then you Vue.use() it. This does Velocity(Vue) basically, which does nothing since Vue is not a HTMLElement Then the plugin ends, and we are back to the real world.

I think you may have meant @Samuell1 😃