Raphael
Raphael

Reputation: 1812

Uncaught ReferenceError: ClassicEditor is not defined(ckeditor5)

I am trying to setup the ckeditor5 in my local but I am facing this error

Uncaught SyntaxError: Invalid or unexpected token sample.html:14 Uncaught ReferenceError: ClassicEditor is not defined

Below is the local code.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CKEditor 5 – Classic editor</title>
<script src="ckeditor1.js"></script>
</head>
<body>
<h1>Classic editor</h1>
<textarea name="content" id="editor">
    &lt;p&gt;This is some sample content.&lt;/p&gt;
</textarea>
<script>
    ClassicEditor
        .create( document.querySelector( '#editor' ) )
        .catch( error => {
            console.error( error );
        } );
</script>
</body>
</html>

But the same is working when I am pointing to cdn ckeditor url:

https://cdn.ckeditor.com/ckeditor5/12.3.0/classic/ckeditor.js

working cdn jsfiddle

Upvotes: 7

Views: 22706

Answers (4)

Joy Kumar Bera
Joy Kumar Bera

Reputation: 344

This is worked for me

window.addEventListener("load", (e)=>{
    ClassicEditor.create( document.querySelector( '#editor' ) )
    .then( editor => {
        console.log( editor );
    } )
    .catch( error => {
        console.error( error );
    } );
});

Upvotes: 4

Erfan Paslar
Erfan Paslar

Reputation: 120

I had the same problem but when I looked in the files I found a folder called
📂sample and in that folder there was an 'index.html' file and when I opened it on my browser that was an sample if the editor.

And you can look at the script section or just copy that.

also in the body tag according to that index.html you shoul add data-editor="ClassicEditor"

Hope you got your answer.

Upvotes: 1

Russell
Russell

Reputation: 1

There's a map file in the build that has to be included in the root. ckeditor.js.map this had worked for me.

Upvotes: 0

Clarity
Clarity

Reputation: 10873

It's not working because you don't have editor script loaded, so there's no ClassicEditor.

You need to load the editor from cdn first: <script src="https://cdn.ckeditor.com/ckeditor5/12.3.1/classic/ckeditor.js"></script>

Upvotes: 8

Related Questions