12

I use cygwin on windows 8.1 to have an Unix shell. But I cannot run commands such as npm from it.

What should I do to do it? Add some kind of env var to cygwin? Why it doesn't use windows PATH?

Edit: Actually I think that I misunderstood the problem here. It looks like npm is found by cygwin but it cannot be used. For instance I can use git from cygwin without any trouble.

$ npm
/cygdrive/d/Logiciels installés/nodejs/npm: line 2: $'\r' : command not found
/cygdrive/d/Logiciels installés/nodejs/npm: line 4: $'\r' : command not found
/cygdrive/d/Logiciels installés/nodejs/npm: line 5: Syntax error around « $'in\r' »
'cygdrive/d/Logiciels installés/nodejs/npm: line 5: `case `uname` in

So, it looks actually more like a npm issue.

shrewmouse
  • 5,338
  • 3
  • 38
  • 43
Vadorequest
  • 16,593
  • 24
  • 118
  • 215
  • I would not -personally- recommend using Cygwin anymore. I now use Babun, which is an enhanced Cygwin + Zsh for windows! http://babun.github.io/ – Vadorequest Jun 03 '16 at 08:49
  • As you can see from the error message, `npm` (which must be a script in some shell language) contains carriage returns. You can verify this with the hex editor of your choice (or with `xxd`) and remove them with `dos2unix`. However I wondered **how** you had installed `npm` that you ended up with these weird line endings. – user1934428 Mar 09 '22 at 07:12

3 Answers3

27

This seems to be a problem with the npm script as mentioned here, https://github.com/joyent/node/issues/5912

Assuming you have installed nodejs in the default location you can run the following dos2unix command and fix the error.

dos2unix c:/Program\ Files/nodejs/npm

This fixed my problems with the npm script.

Tharaka
  • 2,355
  • 1
  • 20
  • 22
  • Didn't know about dos2unix before! That helped me a ton - thanks! – bodecker Jul 09 '14 at 18:54
  • 1
    On Windows you can find dos2unix.exe here with a few other soft (unix2dos, ..) http://sourceforge.net/projects/dos2unix/?source=typ_redirect Just put the extracted folder somewhere in C:\ and add the path to the PATH environment variable. – Vadorequest Aug 18 '14 at 23:54
  • did not work for me though. any suggestions? would be really appreciated – keinabel Aug 15 '17 at 07:45
  • 1
    There is no 'sudo' in cygwin! – Jerry Miller Jan 29 '18 at 19:51
  • Furthermore, what works in linux, except that it displays nothing but "Loading..." in the browser, crashes on npm start in either cygwin or DOS! So much for any semblance/pretense of portability! – Jerry Miller Jan 29 '18 at 19:53
  • Only in /cygdrive/c/Share/node_modules_cygwin: @ngtools (i.e., no such buggy code in Linux!) – Jerry Miller Jan 29 '18 at 20:05
6

How to make cygwin work with npm command

  1. install http://nodejs.org/#download
  2. download http://nodejs.org/dist/npm/
  3. extract npm.zip into node.exe
  4. run cygwin terminal again

That is it!

Piseth Sok
  • 1,789
  • 1
  • 20
  • 24
1

In order to fix the npm script to work even with dos encoding, i submitted a patch.