#1067·yargs

commandDir does not work with Typescript files

Author: JunkernCreated Feb 9, 2018Updated Aug 2, 2026
Labelstriageddocs

I am using commandDir:

require('yargs')
  .commandDir('cmds')
  .demandCommand()
  .help()
  .argv

Under cmds there is one file with

const command = 'get <source> [proxy]'

const describe = 'make a get HTTP request'

const builder = {
  banana: {
    default: 'cool'
  },
  batman: {
    default: 'sad'
  }
}

const handler = function (argv) {
  // do something with argv.
}

module.exports = { command, describe, builder, handler }

If the file is a .js file it gets correctly loaded by yargs. When I rename the file ending to .ts it is completely ignored :(

Edit: The following works:

require('yargs')
  .command(require('./cmds/addFakeProvider'))
  .demandCommand()
  .help()
  .argv

Am I missing something here?