heapwolf / prompt-sync

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

Doesn't work with nodemon #50

Open wyckster opened 2 years ago

wyckster commented 2 years ago

Steps to reproduce

app.js

console.log(require('prompt-sync')()('Enter anything: '));

To run:

nodemon app.js

This app doesn't exit.

Expected output:

Enter anything: a
a
[nodemon] clean exit - waiting for changes before restart

Actual output:

Enter anything: a
Enter anything: a
                   b
Enter anything: a
b
                      c
Enter anything: a
b
c

But running directly in node works correctly:

node app.js
seanmcclory commented 2 years ago

+1

jalder89 commented 2 years ago

I've noticed an issue with the package not working in nodemon as well. However, I get an error regarding index.js in the prompt-sync package, which causes the app to crash and then nodemon monitors like normal. I don't get the hang where input is prompted, mine crashes before the prompt is displayed.

Usage

I'm requiring the package in my input.js file and then using prompt inside of an arrow function, like this:

const prompt = require('prompt-sync')()

const getInput = (callback) => {

    let input = prompt('Please enter your location: ')

    callback(input)
}

I then call getInput like this:

const input = require('./input')
input.getInput((input) => { doSomething}

Error

When running with nodemon, I get this error and stack trace:

/Users/wbarnes/Documents/Software Development/Node/Node-Course/weather-app/node_modules/prompt-sync/index.js:68
    if (!wasRaw) { process.stdin.setRawMode(true); } 

TypeError: process.stdin.setRawMode is not a function
    at prompt (/Users/wbarnes/Documents/Software Development/Node/Node-Course/weather-app/node_modules/prompt-sync/index.js:68:34)
    at Object.getInput (/Users/wbarnes/Documents/Software Development/Node/Node-Course/weather-app/input.js:6:17)

Tests

If I comment out prompt('Please enter your location: ') nodemon works without issues.

When running the app using node, the app works fine and no errors are presented. I receive the prompt in the CL as expected and then doSomething.

Version

ahmadalzoubi13579 commented 1 year ago

@wyckster any update ?

smkun commented 2 months ago

this issue is still happening

smkun commented 2 months ago

Here is a work around that works. create a nodemon.json folder with this code

{ "stdin": false }