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

referencing the cjs version instead of the esm version? #150

Closed
addlistener opened this issue Aug 28, 2023 · 6 comments
Closed

referencing the cjs version instead of the esm version? #150

addlistener opened this issue Aug 28, 2023 · 6 comments

Comments

@addlistener
Copy link

addlistener commented Aug 28, 2023

Check the code here

cliui/lib/cjs.ts

Lines 3 to 5 in af3145d

const stringWidth = require('string-width')
const stripAnsi = require('strip-ansi')
const wrap = require('wrap-ansi')

Should we require strip-ansi-cjs instead of strip-ansi?

Here are my errors

$ ts-node vspec.ts --input ../test_data --output out
/Users/ajc/hacking/proj/node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/ajc/hacking/proj/node_modules/string-width/index.js from /Users/ajc/hacking/proj/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /Users/ajc/hacking/proj/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.

=> Found "cliui@8.0.1"
info Reasons this module exists
   - "yargs" depends on it
   - Hoisted from "yargs#cliui"
info Disk size without dependencies: "64KB"
info Disk size with unique dependencies: "348KB"
info Disk size with transitive dependencies: "552KB"
info Number of shared dependencies: 6
✨  Done in 0.12s.


=> Found "yargs@17.7.2"
info Has been hoisted to "yargs"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "472KB"
info Disk size with unique dependencies: "1MB"
info Disk size with transitive dependencies: "1.31MB"
info Number of shared dependencies: 12
@shadowspawn
Copy link
Member

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.

"string-width": "^4.2.0",

@shadowspawn
Copy link
Member

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)

@addlistener
Copy link
Author

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

@shadowspawn
Copy link
Member

Is your problem resolved now @addlistener ? (I think it might be from your comment, but making sure!)

@addlistener
Copy link
Author

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.

@shadowspawn
Copy link
Member

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.

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

2 participants