I'm trying to build a custom plugin to CKEditor5 in a react application. I've mainly followed these 2 tutorials:
- https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/react.html
- https://ckeditor.com/docs/ckeditor5/latest/framework/guides/plugins/creating-simple-plugin-timestamp.html
Here is what my code looks like so far:
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { CKEditor } from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
class Timestamp extends Plugin {
init() {
console.log( 'Timestamp was initialized.' );
}
}
function App() {
return (
<div className="App">
<h2>Using CKEditor 5 build in React</h2>
<CKEditor
editor={ ClassicEditor }
config={ {
plugins: [ Timestamp ],
toolbar: [ 'bold', 'italic' ]
} }
data="<p>Hello from CKEditor 5!</p>"
onReady={ (editor: any) => {
// You can store the "editor" and use when it is needed.
console.log( 'Editor is ready to use!', editor );
} }
onChange={ ( event: any, editor: { getData: () => any; } ) => {
const data = editor.getData();
console.log( { event, editor, data } );
} }
onBlur={ ( event: any, editor: any ) => {
console.log( 'Blur.', editor );
} }
onFocus={ ( event: any, editor: any ) => {
console.log( 'Focus.', editor );
} }
/>
</div>
);
}
export default App;
I keep getting a white screen and this error in the console though:
Uncaught CKEditorError: ckeditor-duplicated-modules
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-ckeditor-duplicated-modules
at ./node_modules/@ckeditor/ckeditor5-utils/src/version.js (version.js:144:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./node_modules/@ckeditor/ckeditor5-utils/src/emittermixin.js (ckeditorerror.js:195:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./node_modules/@ckeditor/ckeditor5-utils/src/observablemixin.js (mix.js:48:1)
at options.factory (react refresh:6:1)
The documentation on the error code (duplicated modules) doesn't tell anything about custom plugins (only imported plugins). From what I can see here (https://ckeditor.com/docs/ckeditor5/latest/framework/guides/tutorials/using-react-in-a-widget.html) it should be doable.
Does anyone know what I'm doing wrong?
Okay, I should've read the documentation more carefully.. essentially you have to update your webpack configs if you're working in a repo generated from create-react-app. There is a thorough guide here: https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/react.html#using-create-react-app3
Here's what my
rulesblock looks like in my./config/webpack.config.jsfile: