How to Install Vue Packages in nuxt.js

11,680

To fix this, create a file called vueTyper.client.js under plugin folder then type this;

import Vue from 'vue';
import { VueTyper } from 'vue-typer';

Vue.component('vue-typer', VueTyper);

then in your nuxt.config.js add this to your plugin

plugins: [
  {src: '~/plugins/vueTyper.client.js', mode: 'client',}
]

after doing this you can easily use it anywhere in your application without error:

<vue-typer text='Hello World! I was registered locally!'></vue-typer>
Share:
11,680
Kelvin Fernando
Author by

Kelvin Fernando

Updated on June 04, 2022

Comments

  • Kelvin Fernando
    Kelvin Fernando almost 2 years

    I'm trying to install Vue Typer in my Nuxt js app but no luck. I keep getting "document not defined". I tried importing it in my nuxt.config.js as a plugin but it doesn't work.

    I got it working in my VueCLI 3, seems to work fine with this method.

    Appreciate it!

    Getting

    NuxtServerError render function or template not defined in component: anonymous

    ////plugins///
    
    import Vue from vue;
    
    if (process.client) {
       const VueTyper = require('vue-typer');
       Vue.use(VueTyper);
    }
    
    ///nuxt.config.js///
    
    plugins: [
        {src: '~/plugins/vue-typer.js', ssr: false}
      ],
    <template>
        <vue-typer text='Hello World! I was registered locally!'></vue-typer>
    </template>
    
    <script>
    const VueTyper = processs.client ? require('vue-typer'): '';
    export default {
        components: {
           VueTyper
        }
    }
    </script>
  • CodeSpent
    CodeSpent over 4 years
    Just a note it should be import Vue from 'vue';. Too small for an edit, most will figure it out but worth noting. :)
  • Jonathan Arias
    Jonathan Arias almost 4 years
    What if I just want to use it in a page and dont want to register it as a plugin?
  • kissu
    kissu about 3 years
    Since Nuxt.js 2.4, ssr : false is deprecated and mode: 'client' should be used instead as shown here: nuxtjs.org/docs/2.x/configuration-glossary/…