ERR_REQUIRE_ESM with Vitest when using ckeditor5-react and ckeditor5-build-classic
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/@[email protected]/node_modules/@ckeditor/ckeditor5-watchdog/src/index.js from /workspaces/workspace/node_modules/.pnpm/@[email protected]_@[email protected]_@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/@[email protected]/node_modules/@ckeditor/ckeditor5-watchdog/src/index.js in /workspaces/workspace/node_modules/.pnpm/@[email protected]_@[email protected]_@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/@[email protected]_@[email protected]_@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
I have same issue, Did you find any solution @f4irline ?
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.