ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.44k stars 3.69k forks source link

Jest - CKEditorError: ckeditor-duplicated-modules #16665

Closed DuIIDa closed 1 month ago

DuIIDa commented 3 months ago

I had this problem when running tests(Jest) after migrating from ckeditor4 to ckeditor5. image

package.json

"dependencies": { ... "@ckeditor/ckeditor5-react": "^8.0.0", "ckeditor5": "^42.0.0", ... } "jest": { "resetMocks": false, "collectCoverageFrom": [ "*/.{js,jsx,ts,tsx}", "!/integration-tests/", "!/node_modules/", "!/vendor/", "!src/old/", "!src/stories/" ], "watchPathIgnorePatterns": [ "\integration-tests\" ], "transformIgnorePatterns": [ "!node_modules/" ], "moduleNameMapper": { "\.(css|less|scss|sass)$": "identity-obj-proxy" } },

My imports:

import { Bold, Essentials, Italic, Mention, Paragraph, Undo, Underline, Strikethrough, RemoveFormat, List, BlockQuote, Link, Table, TableToolbar, Heading, } from 'ckeditor5'; import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import { CKEditor } from '@ckeditor/ckeditor5-react'; // eslint-disable-next-line import/no-unresolved import 'ckeditor5/ckeditor5.css';

I also tried importing ClassicEditor from ckeditor5.

Witoso commented 3 months ago

Hi! ClassicEditor should be pulled from ckeditor5 as well. What error did you see then?

DuIIDa commented 3 months ago

Hi! When import directly from ckeditor5 I get the same error. Imports: import { ClassicEditor, Bold, Essentials, Italic, Mention, Paragraph, Undo, Underline, Strikethrough, RemoveFormat, List, BlockQuote, Link, Table, TableToolbar, Heading, } from 'ckeditor5'; import { CKEditor } from '@ckeditor/ckeditor5-react';

image

Reinmar commented 3 months ago

Which version of @ckeditor/ckeditor5-react and ckeditor5 packages do you use? Are you sure that both are installed in the latest available versions?

Second thing to check: You should have no imports from @ckeditor/* packages expect the react one. In other words, the only imports should happen from @ckeditor/ckeditor5-react and ckeditor5.

DuIIDa commented 3 months ago

I tihs version: image

I found a solution for myself. But I'm not sure it's correct Inside the test: jest.mock('File with CKEditor');

Reinmar commented 2 months ago

Based on the snippets that you provided, all seems to be correct. I have no idea why you get the dup-modules error. But it's a one that can be triggered by things that are hard to spot.

Would you be able to compile a small sample project where this issue is reproducible?

CKEditorBot commented 2 months ago

The issue lacks the feedback we asked for two weeks. Hence, we've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

CKEditorBot commented 1 month ago

We've closed your issue due to inactivity. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).