Skip to content

Deno: yargs.env() fails #2136

@pvormittag

Description

@pvormittag

The following error is thrown after adding .env() to yargs when using Deno and deno run --allow-env ...:

error: Uncaught TypeError: Cannot convert undefined or null to object
            Object.keys(env).forEach(function (envVar) {
                   ^
    at Function.keys (<anonymous>)
    at applyEnvVars (https://deno.land/x/yargs_parser@v20.2.4-deno/build/lib/yargs-parser.js:661:20)
    at YargsParser.parse (https://deno.land/x/yargs_parser@v20.2.4-deno/build/lib/yargs-parser.js:356:9)
    at Function.yargsParser.detailed (https://deno.land/x/yargs_parser@v20.2.4-deno/deno.ts:32:17)
    at YargsInstance.[runYargsParserAndExecuteCommands] (https://deno.land/x/yargs@v17.3.1-deno/build/lib/yargs-factory.js:1313:86)
    at YargsInstance.parse (https://deno.land/x/yargs@v17.3.1-deno/build/lib/yargs-factory.js:692:63);

This error will occur even with the current Deno example in the readme:

import yargs from 'https://deno.land/x/yargs/deno.ts'
import { Arguments } from 'https://deno.land/x/yargs/deno-types.ts'

yargs(Deno.args)
  .env() // <---- Adding .env() causes the error to throw.
  .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)
  .parse()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions