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

Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported. #159

Open
marikaner opened this issue Apr 24, 2024 · 7 comments
Open

Comments

@marikaner
Copy link

marikaner commented Apr 24, 2024

We use cliui transitively through jest, which is a CJS module. Currently, when running jest in our project, we get the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/node_modules/string-width/index.js from [...]/node_modules/cliui/build/index.cjs not supported.

I believe this is because of these lines.
Instead string-width and string-ansi, string-width-cjs' and string-ansi-cjsshould be required. Those are already installed. However, the third dependencywrap-ansi` does not exist as a CJS dependency.

@shadowspawn
Copy link
Member

Short version: Are you using yarn 1? Try upgrading to yarn v1.22.22 or higher.

Long version

The problem isn't actually in this repo. Or at least, not yet.

PR #139 uses package aliases to pull in two different versions of string-width et al to add wrapping support for esm. It is published as @isaacs/cliui from a cliui fork and is used as a dependency of JackSpeak. The aliases can trigger broken dependency resolution with Yarn 1.

@marikaner
Copy link
Author

With a closer look I realized the problem might not be this package because I got the same issue with another. I was in fact using yarn 1.22.19. Thanks for the tip!

mnvr added a commit to ente-io/ente that referenced this issue May 1, 2024
@achimstraussdmb2bcom
Copy link

i use yarn in version 1.22.22 and the problem still persists

@shadowspawn
Copy link
Member

Have you got a reproduction @achimstraussdmb2bcom ?
In case you did not already, you may need to delete an existing lock file and node_modules and do a fresh install to clear the problem.

@JDMathew
Copy link

I was struggling with this issue, I'm not 100% sure what solved it but in the end I got it working on yarn 1.22.22 only after deleting yarn.lock and node_modules

@maludwig
Copy link

I had the same issue, updating to yarn 1.22.22 and this fixed it:

rm -rf node_modules yarn.lock && yarn install

@devmeireles
Copy link

I've just updated to 1.22.22 and it was enough to solve the issue, I was facing this ERR_REQUIRE_ESM on Vite + React +Jest setup

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

6 participants