nasa8x/v-markdown-editor

Window is not defined

Opened this issue · 4 comments

Get a error on Nuxt in node_modules/v-markdown-editor/dist/v-markdown-editor.js:10:
Error:
window is not defined

vjdv commented

i'm having same problem :/

vjdv commented

I made it work this way:

Wrapped with client-only in view:

<client-only>
  <markdown-editor />
<client-only>

Set mode=client in nuxt config:

{ src: '~/plugins/markdown-editor.js', mode: 'client' }

hope it helps!

@vjdv Thanks for the hint! I am also using nuxt but now I get the error
[Vue warn]: Failed to mount component: template or render function not defined..
Do you have any idea how to solve this?

Edit: I accidentally used Vue.component('markdown-editor', Editor) instead of Vue.use(Editor), now it's working fine!
Also it's also possible to use
{ src: '~/plugins/vMarkdownEditor.js', ssr: false }
in nuxt.config.js, so you don't have to use the <client-only> wrapper.

Usually, I use my plugin filename as markdow-editor.client.js. So, automatically Nuxt knows that the plugin must be loaded only in client side. This happen because of *.client.js

// nuxt.config.js
export default {
    plugins: [
        '@/plugins/markdow-editor.client'
    ]
}

That's enougth to solve problems like Window is not defined, since the plugin only will work on client side