iarna / wide-align

ISC License
20 stars 14 forks source link

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

Open svitovyda opened 1 year ago

svitovyda commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

simonmaass commented 10 months ago

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!

jvegax commented 10 months ago

@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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

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

tompato commented 8 months ago

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 commented 5 months ago

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 commented 5 months ago

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)