Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
f4irline opened this issue Apr 30, 2024 · 2 comments

Comments

@f4irline
Copy link

f4irline commented Apr 30, 2024

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

@JinalSinroja
Copy link

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

@filipsobol
Copy link
Member

filipsobol commented Jun 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants