Deno bundle yargsParser initialization failure
See original GitHub issueTrying 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
yargs - npm
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you:.
Read more >docs/api.md | yargs@v16.1.1-deno
Tells the parser that if the option specified by key is passed in, it should be interpreted as a path to a JSON...
Read more >Deno - Mark Volkmann
The deno bundle command bundles all the dependencies of a program into a single file. It takes a .js or .ts file as...
Read more >Yargs The Modern, Pirate-themed Successor to Optimist
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you: commands and (grouped) ......
Read more >esbuild-wasm | Yarn - Package Manager
For example, the yargs package contains the file yargs/yargs which has no extension. Node, Webpack, and Parcel can all understand code that imports ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I found the issue
There is a distinction between the names of an exported value between
deno run
anddeno compile
when importing an object and using it as a key in a new objectThis will create
{yargParser: Parser}
indeno compile
while work as intended withdeno run
where you get{Parser: Parser}
Just tried it again with Deno version 1.6.3 and it appears to have been fixed.