Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
khardix opened this issue Dec 7, 2020 · 2 comments · Fixed by #1825, samchouse/maintainer#157, elirehema/pcapi#23, elirehema/real-estate#34 or vdonoladev/CasaCriativa#8
Labels

Comments

@khardix
Copy link

khardix commented Dec 7, 2020

  • 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);
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Dec 25, 2020
@remy remy removed the stale no activity for 2 weeks label Jan 6, 2021
remy added a commit that referenced this issue Jan 6, 2021
Fixes: #1807

Allows for nodemon --help > help.txt
@remy
Copy link
Owner

remy commented Jan 6, 2021

@khardix that fix was on point - and doesn't really need a test to go along side as it doesn't affect core running. I've got a PR (bit late) but it'll go live today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment