CKEditor5 React中GeneralHtmlSupport插件无法使用报错求助
解决CKEditor5 React中GeneralHtmlSupport插件报错问题
问题根源
你通过在线构建工具生成的自定义编辑器构建已经包含了GeneralHtmlSupport插件,此时再单独导入该插件并手动添加到plugins配置数组中,会触发插件重复注册的冲突,导致控制台报错。
修复步骤
移除冗余的插件导入
删除以下单独导入插件的代码:import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport';调整编辑器配置
无需在plugins数组中手动声明GeneralHtmlSupport,直接配置该插件的HTML规则即可(如果需要自定义支持的HTML标签/属性):import { CKEditor } from '@ckeditor/ckeditor5-react'; import Editor from 'ckeditor5-custom-build/build/ckeditor'; const editorConfiguration = { // 移除原plugins数组,或仅保留构建中已包含的其他插件 htmlSupport: { allow: [ // 示例:允许div标签及指定属性 { name: 'div', attributes: ['class', 'data-*'] } ] } }; // 组件渲染部分 <CKEditor editor={ Editor } config={ editorConfiguration } />确认构建完整性
检查自定义构建的ckeditor5-custom-build/build/ckeditor.js文件,确认GeneralHtmlSupport已被包含在内,确保在线构建时确实勾选了该插件。重启项目生效
清理项目缓存后重启React开发服务,确保配置修改完全生效。
内容的提问来源于stack exchange,提问作者bro crop
相关产品推荐
相关产品推荐

