heapwolf / prompt-sync

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

Autocomplete error #59

Open AlfonsoC06 opened 2 years ago

AlfonsoC06 commented 2 years ago

Code: import prompt from 'prompt-sync';

var gender = prompt('Are you a male or a female? (M - male, F - female)');

if(gender == 'M' || gender == 'F'){ console.log(gender); } else { console.log('Try again!'); }

Error:

var autocomplete = config.autocomplete = ^

TypeError: Cannot create property 'autocomplete' on string 'Are you a male or a female? (M - male, F - female)'

aayusharyan commented 1 year ago

I am not sure about import approach, but I faced a similar issue when using prompt with require. The way it is intended to work is like this.

const prompt_fn = require('prompt-sync');
const prompt = prompt_fn();
mfcastilho commented 1 year ago

I was having the same problem. Your answer helped me a lot! Thanks!

Jolly-Pirate commented 1 year ago

Previously answered https://github.com/heapwolf/prompt-sync/issues/29 for both types of import (require and es6 module).