heapwolf / prompt-sync

a synchronous prompt for node.js
MIT License
211 stars 42 forks source link

TypeError: Cannot create property 'autocomplete' on string #29

Closed GNUGradyn closed 6 years ago

GNUGradyn commented 6 years ago

Code:

    config.token = prompt('No token is set! Please create your bot at discordapi.com and paste the token here (see (git page) for more help with this): ')

result:

C:\Users\(username)\Documents\(project name)\node_modules\prompt-sync\index.js:20
  var autocomplete = config.autocomplete =
                                         ^

TypeError: Cannot create property 'autocomplete' on string 'No token is set! Please create your bot at discordapi.com and paste the token here (see (github URL) for more help with this): '
    at create (C:\Users\(username)\Documents\(project name)\node_modules\prompt-sync\index.js:20:42)
    at Object.<anonymous> (C:\Users\(username)\Documents\\index.js:33:20)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
ingalls commented 6 years ago

@GNUGradyn You must instantiate a new prompt instance before you can use it.

Per the examle

const promp = require('promp-sync')();

which sets prompts as a function with the default settings

alternatively

const promp = require('promp-sync')({
    'fake_val': 'OPTIONAL CONFIG VALUES HERE'
});

Will let you change the default config options

Pawel-Stankiewicz commented 2 years ago

What about import? I get the same error with:

import prompt from 'prompt-sync';
const name = prompt('What is your name?');
console.log(`Hey there ${name}`);

  var autocomplete = config.autocomplete =
                                         ^
TypeError: Cannot create property 'autocomplete' on string 'What is your name?'
Disha644 commented 2 years ago

@Pawel-Stankiewicz, this will work in case of import import promptSync from 'prompt-sync'; const prompt = promptSync(); const name = prompt('Name: ');

AhmadKalash2000 commented 4 months ago

I'm doing an import but getting the same error: Cannot create property 'autocomplete' on string The code is:

const prompt = require("prompt-sync")();

const deposit = () => { const depositAmount = prompt("Enter a deposit amount: "); };

deposit();