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 _stringWidth is not a function #155

Open
DopamineDriven opened this issue Feb 21, 2024 · 2 comments
Open

error _stringWidth is not a function #155

DopamineDriven opened this issue Feb 21, 2024 · 2 comments

Comments

@DopamineDriven
Copy link

I use this package in an internal package I wrote for my org. While executing the pipeline, I ran into an error stating that _stringWidth is not a function in file node_modules/cli-progress/lib/formatter.js at line 57:

    const fullMargin = Math.max(0, params.maxWidth - _stringWidth(s) -2);

Upon looking into this file, I noticed that the following import isn't destructured/doesn't key-into the default object

const _stringWidth = require('string-width');

possible workarounds:
(1)

const { default: _stringWidth } = require('string-width');

(2)

const _stringWidth = require("string-width").default;

Instead, I only changed line 57 as follows:

const fullMargin = Math.max(0, params.maxWidth - _stringWidth.default(s) -2);

Which resolved the error.


Type note:

The required _stringWidth const has an alias of

(alias) const _stringWidth: {
    (string: string): number;
    default: typeof stringWidth;
}
import _stringWidth

Contents of output patch file from running yarn patch-package cli-progress using the patch-package npm package

diff --git a/node_modules/cli-progress/lib/formatter.js b/node_modules/cli-progress/lib/formatter.js
index 8ca662d..c59287a 100644
--- a/node_modules/cli-progress/lib/formatter.js
+++ b/node_modules/cli-progress/lib/formatter.js
@@ -54,7 +54,7 @@ module.exports = function defaultFormatter(options, params, payload){
     });
 
     // calculate available whitespace (2 characters margin of error)
-    const fullMargin = Math.max(0, params.maxWidth - _stringWidth(s) -2);
+    const fullMargin = Math.max(0, params.maxWidth - _stringWidth.default(s) -2);
     const halfMargin = Math.floor(fullMargin / 2);
 
     // distribute available whitespace according to position
@AndiDittrich
Copy link
Member

Hi @DopamineDriven

see #143
the package will be dropped with the next major release

@crtl
Copy link

crtl commented May 14, 2024

Hi @DopamineDriven

see #143 the package will be dropped with the next major release

When will this be?

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

3 participants