14

I have no trouble running node.exe from a regular command prompt:

C:\>node --interactive
> console.log("Works fine");
Works fine

But when I try to do the same thing from a Cygwin console, I run into this:

Olli@Olli-MBRr /cygdrive/c
$ node.exe

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: read ENOTCONN
    at errnoException (net.js:900:11)
    at Socket._read (net.js:391:21)
    at Socket.Readable.read (_stream_readable.js:320:10)
    at Socket.read (net.js:293:43)
    at new Socket (net.js:185:10)
    at process.stdin (node.js:660:19)
    at startup (node.js:145:16)
    at node.js:901:3

At first I thought it might be because Cygwin has trouble with the path name with a space in it (C:\Program Files\nodejs), but after installing node.js to a directory with no spaces in the path name I was unable to resolve the problem.

I would like to run a Node JS console from Emacs (run from Cygwin) using js-comint, but I ran into this error and have no clue how to resolve it.

luxbock
  • 185
  • 1
  • 2
  • 5
  • Regarding your ending point quote(I would like to run a Node JS console from Emacs (run from Cygwin) using js-comint): (1) I have the same goal except within Emacs' M-x "shell" (I'm unfamiliar with js-comint), (2) regarding your goal -except seemingly sadly without Cygwin-, the [Google Search(node emacs shell)](http://google.com/search?q=node+emacs+shell) which find 3 finds me this page I see also has as find 1 [(Emacs wiki for Node.js )Using js-comint](http://www.emacswiki.org/emacs/NodeJs#toc2). – Destiny Architect May 11 '14 at 03:28
  • HEADS UP: 1.5 years before this asking, this question was essentially already asked at [stackoverflow.com/questions/10043177/node-js-cygwin-not-supported](http://stackoverflow.com/questions/10043177/node-js-cygwin-not-supported); SO SEE THAT FIRST and KINDLY PUT SOLUTIONS *THERE* --unless they were started here first, as [Running from Cygwin.bat]( http://stackoverflow.com/a/23030836/2255628): then it seems best to keep the details here (since started here) and just link to them from there; there already has a number of answers not found here. – Destiny Architect May 11 '14 at 03:45
  • Regarding your ending goal quote(**run a Node JS console from Emacs[ on Windows]**), for NOT or not-just quote((run from Cygwin) using js-comint), see also [stackoverflow.com/questions/8909836/how-to-run-node-js-interactively-in-emacs-on-windows](http://stackoverflow.com/questions/8909836/how-to-run-node-js-interactively-in-emacs-on-windows) asked 1.1 years before this Q asked. – Destiny Architect May 11 '14 at 06:07

5 Answers5

22

It won't work from a cygwin console, but it WILL work in a cygwin shell if you run it from a windows console. Just open a command prompt and run Cygwin.bat to get the shell. Then you can run node.

According to this cygwin's console isn't a real console, it's a pipe in disguise.

Bill Burdick
  • 935
  • 10
  • 15
  • 1
    Yes,I now 1st tried it &worked for me(so I give answer +1 :-). Specifically in Windows,I run"C:\cygwin64\Cygwin.bat" gives session quote( $ node --version v0.10.28 $ node > [runs normally where w/“Cygwin64 Terminal” I get failure similar to Q] ). Going BEYOND Q to the best console env I know, quote( $ emacs [M-x “shell”] $ node net.js:156 this._handle.open(options.fd); ^ Error: EINVAL, invalid argument at new Socket (net.js:156:18) at process.stdin (node.js:664:19) at startup (node.js:145:16) at node.js:906:3 $) -THAT still no work but super useful if did! – Destiny Architect May 11 '14 at 03:09
  • As [a more complex fix, one can also use Console2 to run Cygwin](http://stackoverflow.com/a/17416869/2255628). – Destiny Architect May 11 '14 at 04:42
  • [This situation (mintty terminal won't work for node) noted by paulcw on an official Node issue report](https://github.com/joyent/node/issues/6459#issuecomment-34620129). – Destiny Architect May 11 '14 at 04:44
6

I think this is caused by using the win distro in cygwin , since cygwin emulates a *nix environment and node.js for windows looks for the win libraries not the nix ones. In order for node.js to work in cygwin you have to build it yourslef. Also latest versions do no work on cygwin.

Current status from official wiki: Cygwin is no longer supported, despite being POSIX compliant. The latest version that compiles is 0.4.12

https://github.com/nodejs/node/wiki/Installation#building-on-cygwin

Victor Yarema
  • 1,183
  • 13
  • 15
Avner Solomon
  • 1,486
  • 11
  • 17
  • Aha I see. I don't want to use an older build that will not be updated in the future, so I have elected to just swap between running GNU Emacs from Windows / Cygwin depending on what I'm doing. – luxbock Jun 25 '13 at 18:54
  • I don't use Emacs , but can't you use Emacs windows version? – Avner Solomon Jun 25 '13 at 18:56
6

A similar problem happens when trying to connect from Ubuntu box to windows/cygwing/sshd over ssh.

After fixing the path, running

node

seem to hang (ignore all input) but respond to kill by ctrl-C

However running

node --interactive

works fine, except the EOF character seems to be ctrl-Z rather then the normal unix/cygwin ctrl-D

QT-1
  • 900
  • 14
  • 21
  • Thanks for that! I never thought of using c-Z, though, in retrospect, it make sense. Even without cygwin support, it seems like it'd be easy to interpret c-D in addition to c-Z. :-( – bill.lee Mar 16 '17 at 03:58
4

Node.js dropped support for Cygwin since long ago. I've tried using some older version, but it now means a lot of problems with npm and basically every other library you can install through the manager.

What I did: wrote a Windows shell script translating paths into Windows-like paths, but it's a really quick and dirty job, so I won't share it yet. Then I symlinked this bat file in /usr/bin and this is how I'm calling it now. Also, I think I'm starting the REPL there immediately, because the Node version that I have doesn't do it on its own by default.

I've tried building it, but the build is very messy. They've used SCons and some other library on top of it, and that library is somehow out of date now (I'm using SCons for other projects, so I didn't try to downgrade it).

Bottom line, if you just need a JavaScript interpreter in Emacs - try Mozrepl, Node.js just doesn't want to play nice with it.

0

Using rlwrap node --interactive solved it for me. The --interactive switch keeps it from hanging, and rlwrap fixes quirks with history navigation, etc.

Note: you may need to install rlwrap through Cygwin's package manager.

Dominykas Mostauskis
  • 7,797
  • 3
  • 48
  • 67