question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deno bundle yargsParser initialization failure

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
seivancommented, Mar 23, 2021

I think I found the issue

There is a distinction between the names of an exported value between deno run and deno compile when importing an object and using it as a key in a new object

export default yargsParser
import Parser from 'https://deno.land/x/yargs_parser@v20.2.4-deno/deno.ts';

const newObject = {
 Parser
}

This will create {yargParser: Parser} in deno compile while work as intended with deno run where you get {Parser: Parser}

1reaction
nchudleighcommented, Jan 2, 2021

Just tried it again with Deno version 1.6.3 and it appears to have been fixed.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found