11

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>

3
  • Please read nuxtjs doc. Modules is for nuxt modules, not random node package. You need plugin with ssr false option. It's all covered in nuxt docs Commented Feb 5, 2019 at 1:34
  • 1
    Unfortunately it doesnt look like this package can be used in nuxt please see this open issue on there github github.com/cngu/vue-typer/issues/1 this may give you some more information - With saying that though this functionality would be easy to implement yourself, You could look at this stackOverflow question for inspiration stackoverflow.com/questions/34380037/… Commented Feb 5, 2019 at 23:10
  • Makes sense. Thank you very much, really appreciate the help! Commented Feb 6, 2019 at 2:45

1 Answer 1

33

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Just a note it should be import Vue from 'vue';. Too small for an edit, most will figure it out but worth noting. :)
What if I just want to use it in a page and dont want to register it as a plugin?
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/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.