ckeditor / ckeditor5-react

Official CKEditor 5 React component.
https://ckeditor.com/ckeditor-5
Other
415 stars 98 forks source link

ERR_REQUIRE_ESM with Vitest when using ckeditor5-react and ckeditor5-build-classic #475

Open f4irline opened 2 months ago

f4irline commented 2 months ago

Hey,

When trying to run tests using Vitest and React Testing Library, I stumble on to the following error:

Error: require() of ES Module /workspaces/workspace/node_modules/.pnpm/@ckeditor+ckeditor5-watchdog@41.3.1/node_modules/@ckeditor/ckeditor5-watchdog/src/index.js from /workspaces/workspace/node_modules/.pnpm/@ckeditor+ckeditor5-react@6.3.0_@ckeditor+ckeditor5-core@41.3.1_@ckeditor+ckeditor5-editor-mu_u4cc4mpjbdj7ukcuf4x6qwbloa/node_modules/@ckeditor/ckeditor5-react/dist/index.js not supported.
Instead change the require of /workspaces/workspace/node_modules/.pnpm/@ckeditor+ckeditor5-watchdog@41.3.1/node_modules/@ckeditor/ckeditor5-watchdog/src/index.js in /workspaces/workspace/node_modules/.pnpm/@ckeditor+ckeditor5-react@6.3.0_@ckeditor+ckeditor5-core@41.3.1_@ckeditor+ckeditor5-editor-mu_u4cc4mpjbdj7ukcuf4x6qwbloa/node_modules/@ckeditor/ckeditor5-react/dist/index.js to a dynamic import() which is available in all CommonJS modules.
 ❯ node_modules/.pnpm/@ckeditor+ckeditor5-react@6.3.0_@ckeditor+ckeditor5-core@41.3.1_@ckeditor+ckeditor5-editor-mu_u4cc4mpjbdj7ukcuf4x6qwbloa/node_modules/@ckeditor/ckeditor5-react/dist/index.js:5:122

This is with the latest version of ckeditor5-react and ckeditor5-build-classic. This did work with ckeditor5-build-classic version 39.0.2, but with the latest version there seems to be issues.

A minimal StackBlitz implementation where the error can be reproduced can be found here - just let StackBlitz install the dependencies and run npm run test

JinalSinroja commented 1 month ago

I have same issue, Did you find any solution @f4irline ?

filipsobol commented 2 weeks ago

While we have migrated the editor to ESM, our framework integrations are still UMD bundles that use require(), which seems to cause this problem. Support for require()-ing ESM was added in Node 22, but migrating this package to ESM should fix this issue for all supported Node versions.

As we plan to release a new major soon (adding support for React 19), we may use this opportunity to also migrate to ESM.