Trying to write a cli with Deno, went to go and try the example from the readme and the bundled code fails at runtime.
Works fine if you just deno run main.ts, but the hope was to use the bundled code (compiled to binary) for distribution.
Any ideas on why this may be happening? Wasnt sure if this was more of a Deno issue or a yargs issue, so if I am barking up the wrong tree let me know.
// main.ts
import yargs from 'https://deno.land/x/yargs/deno.ts'
import { Arguments } from 'https://deno.land/x/yargs/deno-types.ts'
yargs(Deno.args)
.command('download <files...>', 'download a list of files', (yargs: any) => {
return yargs.positional('files', {
describe: 'a list of files to do something with'
})
}, (argv: Arguments) => {
console.info(argv)
})
.strictCommands()
.demandCommand(1)
.argv
โฏ deno bundle ./main.ts bundle.js
Bundle main.ts
Check main.ts
Emit "bundle.js" (227.35KB)
โฏ deno run bundle.js
error: Uncaught ReferenceError: Cannot access 'yargsParser' before initialization
yargsParser.camelCase = camelCase;
^
at bundle.js:517:1
@nchudleigh I haven't experimented with Deno much, beyond writing the unit tests to get yargs running on it.
Do you need to explicitly add yargs-parser to the bundle?
Tried that and didnt have any effect, the issue now seems to be cliui access issue.
error: Uncaught ReferenceError: cliui is not defined
cliui: cliui,
I have tried explicitly bundling both of them and it gives the same issue.
I went to the yargs-parser repo and tried the same process of bundling the example in the readme and it had an issue with finding which OS it is on.
error: Uncaught ReferenceError: Cannot access 'isWindows' before initialization
const path = isWindows ? _win32 : _posix;
Perhaps this is a deeper issue with the dependency, in any case I need to dig deeper, going to close until I find something actionable.
Just tried it again with Deno version 1.6.3 and it appears to have been fixed.