英文:
CKEditor5 Online Builder Failed to Render - React Version
问题
我试图在我的React 18应用程序中使用CKEditor5的在线构建器来渲染编辑器,但在我放入我的代码后,编辑器没有渲染,并且在控制台中我看到了以下错误。
ckeditor.tsx:156 TypeError: Cannot read properties of undefined (reading 'create')
at to._createEditor (ckeditor.tsx:169:1)
at Vr._creator (ckeditor.tsx:133:1)
at editorwatchdog.js:115:1
at async to._initializeEditor (ckeditor.tsx:151:1)
at async to.componentDidMount (ckeditor.tsx:102:1)
我遵循了将下载的CKEditor5文件夹放在项目的根目录中的说明。以下是将编辑器集成到React组件中的我的代码:
import { CKEditor } from '@ckeditor/ckeditor5-react';
import { Editor } from 'ckeditor5-custom-build/build/ckeditor';
const DashboardPage = () => {
return (
<>
<div className='card'>
<div className='card-body'>
{/* 开始::编辑器 */}
<div className='mx-auto'>
<CKEditor
editor={Editor}
data="<p>Hello from CKEditor 5!</p>"
onReady={editor => {
// 您可以存储“editor”并在需要时使用它。
console.log('Editor is ready to use!', editor);
}}
onChange={(event, editor) => {
// const data = editor.getData();
// console.log({ event, editor, data });
}}
onBlur={(event, editor) => {
console.log('Blur.', editor);
}}
onFocus={(event, editor) => {
console.log('Focus.', editor);
}}
/>
{/* 结束::编辑器 */}
</div>
</div>
</div>
</>
)
}
这些是使用的CKEditor5版本:
"@ckeditor/ckeditor5-build-balloon": "^38.0.1",
"@ckeditor/ckeditor5-react": "^6.0.0",
"ckeditor5-custom-build": "file:./ckeditor5",
问题在于,我尝试了预构建的classic
、balloon
版本的CKEditor5,它们都在页面上很好地渲染。我做错了什么?
英文:
I was trying to use the CKEditor5's online builder to render the editor in my React 18 app but after I put my code in, the editor did not render and in the console, I saw the following error.
ckeditor.tsx:156 TypeError: Cannot read properties of undefined (reading 'create')
at to._createEditor (ckeditor.tsx:169:1)
at Vr._creator (ckeditor.tsx:133:1)
at editorwatchdog.js:115:1
at async to._initializeEditor (ckeditor.tsx:151:1)
at async to.componentDidMount (ckeditor.tsx:102:1)
I followed the instruction to put the downloaded CKEditor5 folder in the root directory of my project. The following is my code to integrate the editor into the React component,
import { CKEditor } from '@ckeditor/ckeditor5-react'
import { Editor } from 'ckeditor5-custom-build/build/ckeditor';
const DashboardPage = () => {
return (
<>
<div className='card'>
<div className='card-body'>
{/* begin::Editor */}
<div className='mx-auto'>
<CKEditor
editor={Editor}
data="<p>Hello from CKEditor 5!</p>"
onReady={editor => {
// You can store the "editor" and use when it is needed.
console.log('Editor is ready to use!', editor);
}}
onChange={(event, editor) => {
// const data = editor.getData();
// console.log({ event, editor, data });
}}
onBlur={(event, editor) => {
console.log('Blur.', editor);
}}
onFocus={(event, editor) => {
console.log('Focus.', editor);
}
}
/>
{/* end::Editor */}
</div>
</div>
</div>
</>
)
}
These are the versions of the CKEditor5 used,
"@ckeditor/ckeditor5-build-balloon": "^38.0.1",
"@ckeditor/ckeditor5-react": "^6.0.0",
"ckeditor5-custom-build": "file:./ckeditor5",
The thing is that I tried the prebuilt classic
, balloon
versions of CKEditor5 they all render nicely in the page. What did I do wrong?
答案1
得分: 1
我尝试研究了这个CKEditor 5在线构建器。正如他们在文档中提到的:
如果你想使用CKEditor 5在线构建器,请确保未选择看门狗功能。React集成已经将看门狗功能集成到核心中。
你可以尝试下面的代码片段:
<CKEditor
editor={Editor}
data="<p>来自CKEditor 5的问候!</p>"
watchdogConfig={ { crashNumberLimit: 10 } } //尝试添加这个`watchdogConfig`功能
...
/>
更多参考,请查看示例示例。
希望这有所帮助!
英文:
I tried to research this CKEditor 5 online builder. As they mentioned in their docs:
> If you want to use the CKEditor 5 online builder, make sure that the watchdog feature is not selected. The React integration comes with the watchdog feature already integrated into the core.
You could try the below snippet:
<CKEditor
editor={Editor}
data="<p>Hello from CKEditor 5!</p>"
watchdogConfig={ { crashNumberLimit: 10 } } //try to add this `watchdogConfig` feature
...
/>
For more reference, this is a sample example.
Hope this helps!
答案2
得分: 0
无论如何,我意识到了导致问题的真正原因 - 我yarn
安装了多个预构建的编辑器,例如BalloonEditor
和ClassicEditor
,还有我的在线构建的编辑器,以某种方式它们不能共存,因此导致了错误。
将这个信息分享给其他人参考
英文:
Anyway I realised the real issue causing the problem - I yarn
installed multiple prebuilt editors e.g., BalloonEditor
and ClassicEditor
along with my online built editor and somehow they cannot exist together hence causing the error.
Putting this out there for others' reference
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论