npkgz / cli-progress

:hourglass: easy to use progress-bar for command-line/terminal applications
https://www.npmjs.com/package/cli-progress
MIT License
1.09k stars 84 forks source link

error _stringWidth is not a function #155

Open DopamineDriven opened 6 months ago

DopamineDriven commented 6 months ago

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

Hi @DopamineDriven

see https://github.com/npkgz/cli-progress/issues/143 the package will be dropped with the next major release

crtl commented 4 months ago

Hi @DopamineDriven

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

When will this be?