Skip to content

nodemon crashes when --help is redirected to a file #1807

@khardix

Description

@khardix
  • nodemon -v: master: 3d2320f
  • node -v: v14.14.0
  • Operating system/terminal environment: Fedora 33 (Linux), ZSH
  • Command you ran: node bin/nodemon.js --help >help.log

Expected behaviour

No output; help.log contains the help message.

Actual behaviour

$ node bin/nodemon.js --help >help.log
/home/.../nodemon/lib/nodemon.js:42
    process.stdout._handle.setBlocking(true); // nodejs/node#6456
                           ^

TypeError: Cannot read property 'setBlocking' of undefined
    at nodemon (/home/.../nodemon/lib/nodemon.js:42:28)
    at Object.<anonymous> (/home/.../nodemon/bin/nodemon.js:7:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Steps to reproduce

Run the command with the redirect.

Note

The following patch seems to fix the issue; however, since I did not yet dedicated enough time to understand the test suite (I'm not a JavaScript developer), I was unable to add appropriate tests for it. That is also the reason I'm submitting this as a bug report rather than a pull request.

diff --git a/lib/nodemon.js b/lib/nodemon.js
index b3badea..ce649cb 100644
--- a/lib/nodemon.js
+++ b/lib/nodemon.js
@@ -39,7 +39,9 @@ function nodemon(settings) {
   }
 
   if (settings.help) {
-    process.stdout._handle.setBlocking(true); // nodejs/node#6456
+    if (process.stdout.isTTY) {
+      process.stdout._handle.setBlocking(true); // nodejs/node#6456
+    }
     console.log(help(settings.help));
     if (!config.required) {
       process.exit(0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions