You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CKEditor5中使用CKEDITOR类报错:Uncaught ReferenceError: CKEDITOR is not defined

问题原因与解决方法

你遇到的问题核心是版本混淆:

  • 你引入的是CKEditor 5(从CDN地址ckeditor5/38.1.1可判断),但CKEDITOR.replace()是CKEditor 4的专属API。CKEditor 5完全重构了代码结构,不存在CKEDITOR这个全局对象,所以会抛出CKEDITOR is not defined的错误。
  • 你的代码里已经正确使用了CKEditor 5的初始化方式ClassicEditor.create(),但后面叠加了CKEditor 4的代码,导致冲突。

解决步骤

  1. 彻底删除错误的CKEDITOR.replace()代码块,它和CKEditor 5完全不兼容。
  2. 如果要配置extraAllowedContent(对应CKEditor 5的内容过滤规则),直接把配置项放到ClassicEditor.create()的第二个参数里。

修改后的完整代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>CKEditor</title>
        <script src="https://cdn.ckeditor.com/ckeditor5/38.1.1/classic/ckeditor.js"></script>
    </head>
    <body>
        <div id="editor">This is some sample content.</div>
        <script>
            ClassicEditor
                .create( document.querySelector( '#editor' ), {
                    // CKEditor 5中对应extraAllowedContent的配置
                    allowedContent: 'style;*[id,rel](*){*}'
                })
                .then( editor => {
                    console.log( editor );
                })
                .catch( error => {
                    console.error( error );
                });
        </script>
    </body>
</html>

注意:CKEditor 5和CKEditor 4的API、配置体系完全不同,查找资料时要确认内容对应的CKEditor版本,避免混用。

内容的提问来源于stack exchange,提问作者KANAYO AUGUSTIN UG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 02:13:16