Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nuxt.JS + Vuetify] Error after import 'CKEditor5' (window is not defined ) #74

Closed
migaduo opened this issue Jun 17, 2019 · 12 comments
Closed
Labels
resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). type:question

Comments

@migaduo
Copy link

migaduo commented Jun 17, 2019

Hey @ALL,

i get the following Error after put this in my VueJS Application:

'window is not defined'

import CKEditor from '@ckeditor/ckeditor5-vue';

components: {
      ckeditor: CKEditor.component
    },

Did someone know how to fix it?

I'm using "Nuxt.JS/VueJS/Vuetify"

Thanks for the support!

@Mgsy
Copy link
Member

Mgsy commented Jun 17, 2019

Hello, did you follow our Vue.js integration guide?

@Mgsy Mgsy added the pending:feedback This issue is blocked by necessary feedback. label Jun 17, 2019
@migaduo
Copy link
Author

migaduo commented Jun 17, 2019

Yeah, i tried all implementations. :(

@Mgsy
Copy link
Member

Mgsy commented Jun 17, 2019

Okay, so can you provide exact steps which you perform, so we'll be able to reproduce your issue? Also, all the details about your environment will be appreciated.

@pomek
Copy link
Member

pomek commented Jun 17, 2019

Most probably the issue is related to SSR. If so, there is a related issue – ckeditor/ckeditor5#1511.

@Mgsy
Copy link
Member

Mgsy commented Jul 1, 2019

I'm closing it due to a lack of activity.

@Mgsy Mgsy closed this as completed Jul 1, 2019
@Mgsy Mgsy added resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). type:question and removed pending:feedback This issue is blocked by necessary feedback. labels Jul 1, 2019
@usb248
Copy link

usb248 commented Aug 27, 2019

There is any support for SSR in ckeditor, That's why it displays error : window is not defined.
The only clean solution is to use https://nuxtjs.org/guide/plugins#client-side-only but it induces to use it in a global way ... 👎

Edit: After a lot of research
I found a solution (but not tested in IE11 yet...)

  let ClassicEditor
  let CKEditor

  if (process.client) {
    ClassicEditor = require('@ckeditor/ckeditor5-build-classic')
    CKEditor = require('@ckeditor/ckeditor5-vue')
  }else{
    CKEditor = { component : {template:'<div></div>'}}
  }
export default {
...
    components : { 
      ckeditor: CKEditor.component
    }
...
}

in your component's template
<client-only><ckeditor :editor="editor" /></client-only>

@anurag-do
Copy link

anurag-do commented Feb 21, 2020

@usb248 its working thanks.
was searching for 4 hours.

finally got this worked.

page.vue

<template>
  <div id="app">
    <ckeditor :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
  </div>
</template>

<script>
  let ClassicEditor
  let CKEditor

  if (process.client) {
    ClassicEditor = require('@ckeditor/ckeditor5-build-classic')
    CKEditor = require('@ckeditor/ckeditor5-vue')
  } else {
    CKEditor = { component : {template:'<div></div>'}}
  }

  export default {
    components : { 
      ckeditor: CKEditor.component
    },
    data() {
      return {
          editor: ClassicEditor,
          editorData: '<p>Content of the editor.</p>',
          editorConfig: {
              // The configuration of the editor.
          }
      };
    }
  }
</script>

@metrey
Copy link

metrey commented Jul 5, 2021

The solution at #74 (comment) worked on vuejs v2.x & nuxtjs 2.x (latest)!

@kaplanark
Copy link

Unfortunately, I couldn't do what you said in the Nuxt3 version. Could you guide me in this matter?

@m2sahin
Copy link

m2sahin commented Jul 23, 2023

Problem still persists for Nuxt 3

@9uenther
Copy link

I use it this way

<template>
    <client-only>
        <CKEditor 
            v-if="ClassicEditor" 
            v-model="content"
            :editor="ClassicEditor"
        ></CKEditor>
    </client-only>
</template>
<script setup>
    let CKEditor
    let ClassicEditor = ref()

    if (process.client) {
        CKEditor = defineAsyncComponent(() => import('@ckeditor/ckeditor5-vue').then(module => module.component))
        import('@ckeditor/ckeditor5-build-classic').then(e => ClassicEditor.value = e.default)
    }
</script

@N-index
Copy link

N-index commented Jul 28, 2024

I use it this way

<template>
    <client-only>
        <CKEditor 
            v-if="ClassicEditor" 
            v-model="content"
            :editor="ClassicEditor"
        ></CKEditor>
    </client-only>
</template>
<script setup>
    let CKEditor
    let ClassicEditor = ref()

    if (process.client) {
        CKEditor = defineAsyncComponent(() => import('@ckeditor/ckeditor5-vue').then(module => module.component))
        import('@ckeditor/ckeditor5-build-classic').then(e => ClassicEditor.value = e.default)
    }
</script

Doing it this way will make SSR meaningless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:invalid This issue is invalid (e.g. reports a non-existent bug or a by-design behavior). type:question
Projects
None yet
Development

No branches or pull requests

10 participants