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
exception thrown when yargs.parsed.newAliases is undefined #1144
Comments
I just ran into this when trying to answer @varl 's question in #1137. The problem is not parsed being overwritten, but the returned value of require("yargs") having its properties (not its functions) frozen at their inital value (false for parsed). So: const yargs = require("yargs")
yargs.parse()
console.log(yargs.parsed) returns false, whereas: const yargs = require("yargs")
y = yargs.parse()
console.log(y) returns the expected parsed object. This is due to the way singletonify() in index.js is written. I'll try to correct this behavior. |
I am unable to reproduce the issue, so I was probably wrong when thinking it was related to @oscarocornejo I know it's been a while, but could you please give us some sample code reproducing the issue? |
@oscarocornejo, with @mleguen's work investigating this issue, I ultimately opted to deprecated accessing Do you think you can instead use |
That should be fine, thanks guys 👍 |
Closing, as |
I am seemingly getting the same error in 14.0.0. I don't have much to share other than this is how I intialize the code: yargs
.env('ADM')
.commandDir('commands')
.help()
.wrap(80)
.parse(); This is the error that I get: (node:92950) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.help (/Users/gajus/Documents/dev/applaudience/data-manager/node_modules/yargs/lib/usage.js:240:22)
at Object.self.showHelp (/Users/gajus/Documents/dev/applaudience/data-manager/node_modules/yargs/lib/usage.js:432:15)
at Object.Yargs.self.showHelp (/Users/gajus/Documents/dev/applaudience/data-manager/node_modules/yargs/yargs.js:790:11)
at Object.fail (/Users/gajus/Documents/dev/applaudience/data-manager/node_modules/yargs/lib/usage.js:50:17)
at /Users/gajus/Documents/dev/applaudience/data-manager/node_modules/yargs/lib/command.js:239:36
at processTicksAndRejections (internal/process/task_queues.js:85:5) |
Line 240 in 8792d13
Here |
My export const builder = (yargs: Object): void => {
yargs
.options({
'cinema-data-scraper-sources-path': {
demand: true,
description: 'Path to the directory that includes the cinema data scraper sources.',
type: 'string',
},
// [..]
});
}; |
@gajus mind opening a new issue calling out this specific error? |
@gajus actually, I went ahead and reopened this issue with a new title 👍 Can you figure out a reproduction that doesn't involve a command directory? require('./')
.env('ADM')
.command('my-cool-command', 'description', (yargs) => {
yargs
.options({
'cinema-data-scraper-sources-path': {
demand: true,
description: 'Path to the directory that includes the cinema data scraper sources.',
type: 'string',
},
// [..]
});
}, () => {})
.help()
.wrap(80)
.parse(); 👆 the above works correctly for me. |
I have tried a bunch of cases and I cannot replicate this without using command directory. |
Will give it a try tomorrow again. |
I cannot replicate it in a single file, but with commands it is easy: // ./bin.js
require('yargs')
.commandDir('commands')
.parse(); // ./commands/foo.js
module.exports = {
command: 'foo',
desc: '',
builder: () => {},
handler: async () => {
throw new Error('test');
}
};
|
@gajus you're not using using TypeScript are you? I found a bug that throws similar errors to yours, that happens as a result of:
The |
I am not using TypeScript. |
What is the problem with this test case? |
@gajus test case should be fine, haven't dug into it too much yet; was just wondering if something similar is being caused by your example, i.e., all the fields being walked on an yargs instance (will need to dig and see). |
Found something of an issue when using
yargs.showHelp()
L761
it seems that when
self._parseArgs(processArgs)
is called, it is not saving the results toself.parsed
if you put a breakpoint on this line: L1012, you will see that the
self.parsed
property contains the appropriate items.however, after this function is done, on L762,
self.parsed
is set back tofalse
instead of an object. this leads to their being a parse error:TypeError: Cannot convert undefined or null to object
.concat(Object.keys(yargs.parsed.newAliases) || [])
under function:
usage.showHelp(
L240Thanks! 👍
The text was updated successfully, but these errors were encountered: