Tiptap: ReferenceError document is not defined

Created on 1 Apr 2019  路  5Comments  路  Source: ueberdosis/tiptap

I'm trying to use the editor with Nuxt.js but the application returns this error and doesn't start:

Error: ReferenceError document is not defined
File: node_modulestiptap\disttiptap.common.js
Line 850: this.element = document.createElement('div');

Any idea?

bug need repro

Most helpful comment

@jeverduzco create a new editor instance in a Mounted method

data() {
    return {
      editor: null,
    }
  },
  mounted() {
    this.editor = new Editor({
      content: '<p>This is just a boring paragraph</p>',
    })
  }

All 5 comments

@jeverduzco create a new editor instance in a Mounted method

data() {
    return {
      editor: null,
    }
  },
  mounted() {
    this.editor = new Editor({
      content: '<p>This is just a boring paragraph</p>',
    })
  }

Please provide a codesandbox

@philippkuehn It will help to make a small note about Nuxt in the readme; just a copy of the suggestion of @chalecki will work nicely I think ))

FWIW, I was getting this message while using the nuxt Composition API. Was about to open a new issue, when I stumbled on something that works for me. In addition to wrapping in <client-only>:

  setup ({post}: {post: Post}) {
    const editor = ref<Editor>()
    onMounted(() => {
      editor.value = new Editor({content: post.html || ""})
    })
    onBeforeUnmount(() => {
      if (editor.value !== undefined) {
        editor.value.destroy()
      }
    })
    return { editor }
  },

FWIW, I was getting this message while using the nuxt Composition API. Was about to open a new issue, when I stumbled on something that works for me. In addition to wrapping in <client-only>:

  setup ({post}: {post: Post}) {
    const editor = ref<Editor>()
    onMounted(() => {
      editor.value = new Editor({content: post.html || ""})
    })
    onBeforeUnmount(() => {
      if (editor.value !== undefined) {
        editor.value.destroy()
      }
    })
    return { editor }
  },

@shaunc Where exactly do I copy/paste the setup(){} in my vue component?
I'm using Nuxt with Typescript, just so you know.

Much appreciated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pk-pressf1 picture pk-pressf1  路  3Comments

ageeye-cn picture ageeye-cn  路  3Comments

dolbex picture dolbex  路  3Comments

afwn90cj93201nixr2e1re picture afwn90cj93201nixr2e1re  路  3Comments

agentq15 picture agentq15  路  3Comments