Closed addlistener closed 1 year ago
What version of string-width
is being used by cliui
in your project? Check with npm ls string-width
.
In theory it should be string-width@4.2.3
which is not esm.
https://github.com/yargs/cliui/blob/af3145da0ea31738c4715865a6da0ee388a94c74/package.json#L52
The output looks like yarn
. I did a quick check and and also saw expected version of string-width
:
$ yarn add yargs
...
$ yarn why string-width
├─ cliui@npm:8.0.1
│ └─ string-width@npm:4.2.3 (via npm:^4.2.0)
│
├─ wrap-ansi@npm:7.0.0
│ └─ string-width@npm:4.2.3 (via npm:^4.1.0)
│
└─ yargs@npm:17.7.2
└─ string-width@npm:4.2.3 (via npm:^4.2.3)
success Saved lockfile. success Saved 8 new dependencies. info Direct dependencies └─ yargs@17.7.2 info All dependencies ├─ cliui@8.0.1 ├─ get-caller-file@2.0.5 ├─ require-directory@2.1.1 ├─ string-width@4.2.3 ├─ wrap-ansi@7.0.0 ├─ y18n@5.0.8 ├─ yargs-parser@21.1.1 └─ yargs@17.7.2
Yes you are right
Is your problem resolved now @addlistener ? (I think it might be from your comment, but making sure!)
Hmmm...not really. I switched to commander instead
@shadowspawn but thanks for the kind response. The problem occurred when trying to pack the program with https://github.com/vercel/pkg
The pkg packer is trying to pack with commonjs. However string-width is not commonjs. I remember trying aliasing string-width to string-width-cjs and it worked.
Thanks for the clues @addlistener There is a PR open to rework the cjs/esm wrapping support (#143), so the packaging issues if not fixed are likely to be different if that lands!
If you have a reproduction @archonic (saw your thumbs up), feel free to open another issue with new information.
I have the same problem.
I ran yarn add -D concurrently@^8
and then tried to run:
concurrently "yarn next dev" "tunnel.sh"
and got this output:
/code/myproject/node_modules/cliui/build/index.cjs:315
undefined
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /code/myproject/node_modules/string-width/index.js from /code/myproject/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /code/myproject/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object.<anonymous> (/code/myproject/node_modules/cliui/build/index.cjs:291:21) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.4.0
https://github.com/open-cli-tools/concurrently
Thanks.
@ryancwalsh Try upgrading to yarn v1.22.22 or higher. See #159
@shadowspawn Interesting!
I had seen that post already but I know I had upgraded yarn recently and thought I had the latest version (and below you'll see why).
But when I ran yarn -v
I saw 1.22.19.
https://github.com/yarnpkg/yarn/tags shows versions up to 1.22.22.
People at https://github.com/yargs/cliui/issues/159#issuecomment-2128009693 say that 1.22.22 helps.
So I ran npm upgrade --global yarn
(again, if that's the way I originally tried to upgrade and had assumed worked).
But upon closer inspection I guess it did nothing.
Because now that I double-checked (because of your message), I see yarn -v
still shows "1.22.19".
Then I found https://stackoverflow.com/a/55278430/470749 and ran yarn policies set-version
which successfully upgraded yarn.
Then I ran:
rm -rf node_modules/ && rm yarn.lock
yarn && yarn dev
And it works!
You were right.
I apologize for wasting your time. And I appreciate how quick and helpful your response was!
Check the code here https://github.com/yargs/cliui/blob/af3145da0ea31738c4715865a6da0ee388a94c74/lib/cjs.ts#L3-L5
Should we require strip-ansi-cjs instead of strip-ansi?
Here are my errors