-
Notifications
You must be signed in to change notification settings - Fork 992
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
Readme CJS example fails with versions of Node older than 12.17 #1789
Comments
I researched a bit and found that #!/usr/bin/env node
const yargs = require('yargs/yargs')
const { hideBin } = yargs
const argv = yargs(hideBin(process.argv)).argv
if (argv.ships > 3 && argv.distance < 53.5) {
console.log('Plunder more riffiwobbles!')
} else {
console.log('Retreat from the xupptumblers!')
} |
@apoorv-mishra @gpoole I think we should update the docs wherever we use If anyone feels like submitting a patch, we would happily take the contribution 😄 |
There will probably need to be a corresponding update to the types too, because they don't cover this alternative location for |
Could we add a helpers.js instead (alongside helpers.mjs), so the same entry point works for everyone? |
For pre-exports node, that file would be sufficient - for post-exports node, you may want to modify the “require” condition, but the entry point will at least work for CJS already. |
Not sure if this helps and I haven't been able to get to the bottom of it, but I had a go at adding
Since there's an export map for |
@gpoole 12.16 doesn’t look at “exports” at all, that’s why the file needs to be added where pre-exports node can find it. |
If the root is using type module (which I’d discourage), then you can do a |
Yeah, that does seem to be the case, but I was thrown because the Node documentation seemed to me to say conditional exports were introduced in 12.16 (and 13.2.0?). Are the docs wrong there or am I misunderstanding it? Seems like actually 12.17 was the version it was added? |
Added in 12.16 behind a flag; the flag was removed in 12.17. |
Thanks @bcoe! Works perfectly now. |
Using the CJS example code from the README.md seems to fail for me on all Node versions I tried before 12.17 (12.16.1, 12.15.0, 12.14.1 and 11.15.0):
The error varies by version.
12.16.1:
12.14.1 and 12.15.0:
11.15.0:
Works fine in 12.17 and 12.18.
Here's a sample of how I set it up: https://github.com/gpoole/yargs-node-error
The text was updated successfully, but these errors were encountered: