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]: require() of ES Module error on keystone build #9478

Closed
quintal-william opened this issue Feb 16, 2025 · 9 comments · Fixed by #9479
Closed

[ERR_REQUIRE_ESM]: require() of ES Module error on keystone build #9478

quintal-william opened this issue Feb 16, 2025 · 9 comments · Fixed by #9479
Assignees

Comments

@quintal-william
Copy link

I wanted to update my keystone dependencies because the new version supports React 19. Thanks for the update by the way! 🥳

However, when I ran keystone build, I stumbled apon an error I can't seem to get rid of. I'd love your input if possible. Thanks in advance!

Steps to reproduce

  1. Upgrade @keystone-6/core from 6.3.1 to the first release candidate 0.0.0-rc-20250210004303
  2. Upgrade @keystone-6/fields-document from 9.1.1 to the same release candidate 0.0.0-rc-20250210004303
  3. run pnpm keystone build (in my case: pnpm dotenv -- keystone build)
  4. All steps until "Compiled successfully" behave normally.
  5. Observe error: unhandledRejection Error [ERR_REQUIRE_ESM]: require() of ES Module /@keystar/ui/dist/keystar-ui-table.js from /admin-ui/pages/App/dist/keystone-6-core-___internal-do-not-use-will-break-in-patch-admin-ui-pages-App.cjs.js not supported.

It seems that the cli uses the cjs build of the @keystone/core package, which then attempts to import the esm-only @keystar/ui build.

The error does not occur when adding the --no-ui flag to the build command.

System details

  • Linux mint
  • Pnpm 9.3.0
  • Node v22.11.0
@dcousens
Copy link
Member

@quintal-william can you provide an example of the schema that produces this error for you?

@dcousens
Copy link
Member

dcousens commented Feb 17, 2025

@quintal-william are you using Node 22 with require(esm) support?

@quintal-william
Copy link
Author

Thanks for the quick reply! I figured out a from-scratch error repro:

  1. pnpm create keystone-app
  2. cd into the created directory
  3. pnpm add react react-dom @keystone-6/{auth,core,fields-document}@0.0.0-rc-20250210004303
  4. pnpm keystone build

@quintal-william
Copy link
Author

I'm using Node v22.11.0, I don't know what you mean by "require(esm) support"?

@dcousens
Copy link
Member

@quintal-william try 0.0.0-rc-20250217014122

@quintal-william
Copy link
Author

That worked like a charm! Thanks so much for picking this up so quickly 😃😃

@dcousens
Copy link
Member

dcousens commented Feb 17, 2025

And thank you for testing a release candidate build! 💛

@gautamsi
Copy link
Member

this is still a problem.
any import of esm package in Document Field component-blocks cause this to happen.
steps to reproduce

  • clone keystone repo
  • run pnpm i
  • go to examples/document-field-customisation/keystone-server example
  • run pnpm dev

you will be greeted with the ERR_REQUIRE_ESM error complaining about the @keystar/ui/layout and other @keystar/* components used component blocks.

@emmatown
Copy link
Member

That is separate to this issue. That specific example due to the way it's written needs a version of Node.js that has require(esm) (e.g. v22.14.0, any version > 23 I believe and soon to be in v20 (nodejs/node#56927)) and that requirement won't change for that specific example.

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

Successfully merging a pull request may close this issue.

4 participants