dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Strange undefined behavior - TypeError: Cannot read property 'prototype' of undefined #211

Open asiron opened 7 years ago

asiron commented 7 years ago

I get this strange error, when I try to import a JS file, which was written in ES6 and transipled to ES5. I was trying to debug, why exactly inquirer.prompt.prompts[promptType] gives me null and I found out that for some reason after UI._loop goes through all var prompts = ['input', 'checkbox', 'confirm', 'expand', 'list', 'password', 'rawlist']; it then receives key = 'min' ? and consequently var promptType = prompts[key]; is a [Function: val] that returns Infinity or NaN. Very strange, especially that I am rather new to JS.

/Users/asiron/code/ethereum/fincontracts-client/node_modules/vorpal/dist/ui.js:122
      inquirer.prompt.prompts[promptType].prototype.getType = function () {
                                         ^

TypeError: Cannot read property 'prototype' of undefined
    at _loop (/Users/asiron/code/ethereum/fincontracts-client/node_modules/vorpal/dist/ui.js:122:42)
    at new UI (/Users/asiron/code/ethereum/fincontracts-client/node_modules/vorpal/dist/ui.js:149:7)
    at Object.<anonymous> (/Users/asiron/code/ethereum/fincontracts-client/node_modules/vorpal/dist/ui.js:594:10)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

I am using:

node: v7.5.0
npm: 4.1.2
babel-cli: ^6.0.0
babel-preset-env: ^1.1.8
vorpal: ^1.11.4
asiron commented 7 years ago

Problem goes away if I require('vorpal')() before my other files