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

New version of 'string-width' breaks build #63

Open
svitovyda opened this issue May 30, 2023 · 12 comments
Open

New version of 'string-width' breaks build #63

svitovyda opened this issue May 30, 2023 · 12 comments

Comments

@svitovyda
Copy link

svitovyda commented May 30, 2023

Hi!
I'm not using none of your or gauge nor string-width directly in our project, and a simple yarn upgrade pulled into my project new version of string-width and that causes this error on yarn install:

[5/5] 🔨  Building fresh packages...
.../node_modules/wide-align/align.js:2
var stringWidth = require('string-width')
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/string-width/index.js from .../node_modules/wide-align/align.js not supported.
Instead change the require of index.js in .../node_modules/wide-align/align.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (.../node_modules/wide-align/align.js:2:19)
    at Object.<anonymous> (.../node_modules/gauge/lib/render-template.js:2:13)
    at Object.<anonymous> (.../node_modules/gauge/lib/plumbing.js:3:22)
    at Object.<anonymous> (.../node_modules/gauge/lib/index.js:2:16)
    at Object.<anonymous> (.../node_modules/npmlog/lib/log.js:3:13)
    at libs/core/src/lib/collect-uncommitted.ts (.../node_modules/lerna/dist/cli.js:48:29)
    at __init (.../node_modules/lerna/dist/cli.js:11:56)
    at libs/core/src/lib/check-working-tree.ts (.../node_modules/lerna/dist/cli.js:163:5)
    at __init (.../node_modules/lerna/dist/cli.js:11:56)
    at libs/core/src/index.ts (.../node_modules/lerna/dist/cli.js:4516:5)
    at __init (.../node_modules/lerna/dist/cli.js:11:56)
    at packages/lerna/src/index.ts (.../node_modules/lerna/dist/cli.js:9511:5)
    at __require (.../node_modules/lerna/dist/cli.js:14:50)
    at Object.<anonymous> (.../node_modules/lerna/dist/cli.js:9545:3) {
  code: 'ERR_REQUIRE_ESM'

Can you please limit the version string-width in your dependencies for the current major version to 4?

@sidiqmd
Copy link

sidiqmd commented Sep 14, 2023

@svitovyda how did you fix this? I am having the same issue.

The temporary solution is to keep deleting the yarn.lock every time before yarn install.

@KastenBrot
Copy link

Hi, is this still an issue? My builds break the same way @svitovyda mentioned. The workaround @sidiqmd provided is working, but quite annoying.

@simonmaass
Copy link

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

but would be great if this would get fixed!

PikachuEXE added a commit to PikaSer-Cosmos/pikaser-website-main that referenced this issue Jan 23, 2024
@jvegax
Copy link

jvegax commented Jan 23, 2024

@svitovyda how did you fix this? I am having the same issue.

The temporary solution is to keep deleting the yarn.lock every time before yarn install.

Worked for me 👌

@ged-flod
Copy link

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

but would be great if this would get fixed!

Worked for me 👌

@BlakeGardner
Copy link

I am using bcrypt in my project. After upgrading my install fails:

error /workspaces/api/node_modules/bcrypt: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments: 
Directory: /workspaces/api/node_modules/bcrypt
Output:
/workspaces/api/node_modules/wide-align/align.js:2
var stringWidth = require('string-width')
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /workspaces/api/node_modules/string-width/index.js from /workspaces/api/node_modules/wide-align/align.js not supported.
Instead change the require of index.js in /workspaces/api/node_modules/wide-align/align.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/workspaces/api/node_modules/wide-align/align.js:2:19) {
  code: 'ERR_REQUIRE_ESM'
}

Using the package.json resolutions trick mentioned by others fixed it for the time being.

@TabotCharlesBessong
Copy link

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

but would be great if this would get fixed!

Where in the package.json are you adding it

@riddla
Copy link

riddla commented Feb 5, 2024

@TabotCharlesBessong, you can see a lot of examples on GitHub.

Be aware, that resolutions is a yarn feature – this mechanism also exists for npm via overrides

@mamadou-diagne
Copy link

@TabotCharlesBessong You must remove node_modules, yarn.lock and package-lock.json before running yarn or npm install

@tompato
Copy link

tompato commented Mar 13, 2024

If this project does require string-width < 5 for it to work, due to CommonJS vs ESM, could we not prevent transitive dependency issues with other packages by changing package.json to something like:

"dependencies": {
    "string-width-cjs": "npm:string-width@^1.0.2 || 2 || 3 || 4"
  }

And then in the code:

var stringWidth = require('string-width-cjs')

I'm kinda new to all this CommonJS/ESM and package resolution issues though so maybe it doesn't work.

@qfdk
Copy link

qfdk commented Jun 3, 2024

Hello all,

I found a solution and would like to share how to resolve it:

  1. Don;t need to delete yarn.lock
  2. Run yarn why string-width to find the library that uses it as a dependency.
  3. Downgrade this library to the version that works, remove node_modules, and then run yarn install to verify it works.
  4. Use yarn upgrade lib@version to upgrade only this library.

It should work.

Happy coding!

2024-06-03

@ZackPlauche
Copy link

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

but would be great if this would get fixed!

Where in the package.json are you adding it

anywhere

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

but would be great if this would get fixed!

Worked for me, using Nuxt 3 + Storyblok (latest versions to this date)

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