-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[Bug?]: Error [ERR_REQUIRE_ESM]: require() of ES Module string-width/index.js #8994
Comments
I have an issue like this when does not have But when I add a dependency The framework I used: is
My
Environment:
|
I had the same issue when I was running NestJS project with docker and I was able to solve it by deleting the Here is the example of the line I removed in the
|
I had the same issue while setting up a TS library with jest and as @niyodusengaclement mentioned, deleting |
yarn1 appears to struggle with a dependency "string-width". replacing with npm as it's only used in CI for one specific dependency Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". replacing with npm as package manager. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
yarn1 appears to struggle with a dependency "string-width". To prevent CI from breaking, this PR replaces the use of yarn with npm when generating documentation PDF. Issue reported in multiple places such as: yarnpkg/yarn#8994 storybookjs/storybook#22431
but this i completely against the idea from the |
Here the similar problem when executing tests with
we can fix the problem locally by running:
But still the problem exists on our CI/CD machine 😳, we could add yarn upgrade on CI/CD machine or remove yarn.lock but it's not really good practice. Current workaround add to your dependencies jest-cli (not --dev, it's not working)
Waiting for the fix 🙏 We are using the latest version of yarn |
I bumped into the same error today. Deleing the lock file fixed it |
Having the same error as well! |
same here when trying to install cypress |
I have the same error on CI workflow. Deleting yarn.lock isn't a solution. Help please. |
Hey all!
|
@KaneTesta , and what did you use after that, yarn add -D cypress? |
I am currently using yarn v1.22.21. And I too am facing the same Error as OP, in my Angular v17 project |
I've also encountered this issue when running Jest by following the Next.js Jest installation documentation. Removing the lock file fixed the issue temporarily, but it came back again after some time. |
Same error here |
Same error here, we are using graphql-codegen. Problem with string-width package is already described here: dotansimha/graphql-code-generator-community#225 Also hoping for a fix 🙏 |
Error in https://github.com/zetkin/lyra/actions/runs/9234868359/job/25409050260. ``` > lyra-webapp yarn run v1.22.22 $ jest Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/lyra/lyra/node_modules/string-width/index.js from /home/runner/work/lyra/lyra/node_modules/cliui/build/index.cjs not supported. Instead change the require of index.js in /home/runner/work/lyra/lyra/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules. ``` Fix from yarnpkg/yarn#8994 (comment)
I am not sure if this is fixed today, but i saw this error too during running |
I got the same error today with yarn 1.22.22. It seemed to happen after installing an Open API Generator typescript axios client. Regenerating the lock file fixed the issue. |
Ok so it took a while to even wrap my head around what was happening. For me, there was a preliminary warning when using yarn 1.x.x that two versions were attempted to be installed at the same location, and that it could lead to non-deterministic behavior. My first fix was to set resolutions for the indirect libs like this (which works but isn't optimal), and led me down what I think is the right path.
I then found a thread here sindresorhus/string-width#51 where someone mentioned that upgrading yarn fixed the problem. This aligns with what Claude was telling me, that it has to do with my the way my consuming package is resolving packages. That fix (for me after recently pinning both packages with https://volta.sh to node@18) is:
Subsequently, adding and removing my other package no longer causes the My understanding (which could be wrong) is that, during incorrect yarn resolution / collision of libs in a filesystem directory, a version on the file system resulted in an unexpected interface for require/import. Since they were still valid after removing the package based on ranges like |
Deleting yarn.lock, having "type": "module" in compiler options of package.json, having .cjs for jest.confg extension (jest.config.cjs) and jest.setup.js. |
I was able to delete yarn.lock, rename config file to jest.config.ts, rename setup file to jest.setup.ts, rerun yarn and successfully test. |
### What does this PR do? See: yarnpkg/yarn#8994 (comment) TLDR; Issues with string-width depdendencies requires us to pin the versioning for string-width and wrap-ansi since it's using two of the same module. ### Screenshot / video of UI <!-- If this PR is changing UI, please include screenshots or screencasts showing the difference --> N/A ### What issues does this PR fix or reference? <!-- Include any related issues from Podman Desktop repository (or from another issue tracker). --> N/A, on slack. ### How to test this PR? <!-- Please explain steps to reproduce --> Tests should pass / `yarn watch` and `yarn build` should work. Signed-off-by: Charlie Drage <charlie@charliedrage.com>
### What does this PR do? See: yarnpkg/yarn#8994 (comment) TLDR; Issues with string-width depdendencies requires us to pin the versioning for string-width and wrap-ansi since it's using two of the same module. ### Screenshot / video of UI <!-- If this PR is changing UI, please include screenshots or screencasts showing the difference --> N/A ### What issues does this PR fix or reference? <!-- Include any related issues from Podman Desktop repository (or from another issue tracker). --> N/A, on slack. ### How to test this PR? <!-- Please explain steps to reproduce --> Tests should pass / `yarn watch` and `yarn build` should work. Signed-off-by: Charlie Drage <charlie@charliedrage.com>
Self-service
Describe the bug
Everything was working with string-width v3.2.3, until v5.0.1 was added to yarn.lock, after then I get:
Error [ERR_REQUIRE_ESM]: require() of ES Module <path>/node_modules/string-width/index.js
As workaround I use NPM, which adds the
name
to v4.2.3 and thenyarn import
to generate yarn.lock, since my pipeline is all based in yarn. Or if I addname string-width
to v4.2.3 manually then it works.This issue is already reported in storybookjs github:
[https://github.com/storybookjs/storybook/issues/22431]
To reproduce
Having string-width v4.2.3 and v5.0.1 in yarn.lock, run
yarn --pure-lockfile
Environment
Additional context
No response
The text was updated successfully, but these errors were encountered: