Comments (6)
Just to round this out in case anybody has a similar issue. For us, the solution was just to change our import for yargs
from a default import of the sort:
import yargs from 'yargs'
to a namespace import:
import * as yargs from 'yargs'
.
Thanks again for the help! Great project and we just added yargs
autocomplete to our CLI tool as a bonus (since I didn't know it existed before).
from yargs-parser.
I was not able to reproduce this behaviour in a small test program. Both forms shows the help with an error Unknown argument: unknownOption
.
In the linked issue, it mentions "unknown CLI params" and "unknown commands" and "unknown keyword arguments are being caught as expected but positional ones are not". To be clear, is the observed problem with an "option" starting with a -
or --
, or perhaps a non-option argument type?
from yargs-parser.
It's with what y'all call "options". Sorry for the lack of clarity. I'm wondering where things go awry because when I took just our yargs definition that starts here and copy it into a new script and try to run with the noted --datadir
(from our issue), the unknownOption error appears. It's just when we run it with our compiled Typescript code where it doesn't show up.
from yargs-parser.
I managed to reproduce your problem using your tsconfig.json
. The problem is the legacy yargs export does some tricky things, and TypeScript does some tricky things, and they don't always go together.
You can confirm by calling your broken program with unknown option and --help
, and see if ----unknownOption
appears in the help [sic].
node index.js --unknownOption unknownValue --help
See yargs/yargs#2010 (comment) for some research, which does not cover the settings you are using.
As a work-around, you could use a special TypeScript import style that has worked with all the tsconfig settings I have tried:
// import yargs from 'yargs'
import yargs = require("yargs");
See: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
from yargs-parser.
Thank you for the guidance! I will research #2010 further and see if any of those options could work for us as I don't think the import = require...
will work for us with our current build setup. Will circle back here and close things out once I find a solution.
from yargs-parser.
(Thanks for circling back.)
from yargs-parser.
Related Issues (20)
- yargs converts numbers that start with 0x to decimals, even if parse-numbers if false
- lib/yargs-parser.ts:687:17 - error TS2571: Object is of type 'unknown'. HOT 5
- Existence of βnumberβ Key in `Options.arrays` Changes Parsing HOT 1
- Not working with single dash - HOT 2
- Default value of `false` doesn't work for `narg: { flag: 0 }` HOT 2
- Please add missing tags HOT 1
- Repeated config arguments results in a confusing error HOT 1
- Option with three or more trailing hyphens parsed as positional argument
- `halt-at-non-option` is incompatible with `unknown-options-as-args`
- array w/ default breaks requiresArg HOT 1
- Version number check fails on Bun HOT 3
- Yargs parser supports a minimum Node.js version
- 21.1.0 has broken typings HOT 6
- Version 21.1.0 breaks "--"-related configuration HOT 14
- `negation-prefix` does not work with `short-option-groups` HOT 1
- Broken build on fresh clone (developer) HOT 1
- Can't build locally HOT 2
- Incorrect parsing of options with escaped quotes HOT 3
- :robot: Release is at https://github.com/yargs/yargs-parser/releases/tag/yargs-parser-v21.1.1 :sunflower:
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yargs-parser.