Path problems on Windows in cygwin #2465

Closed
pkhpkh opened this Issue May 21, 2012 · 16 comments

Comments

Projects
None yet
8 participants
@pkhpkh
Contributor

pkhpkh commented May 21, 2012

[ Since I can't request a reopening of https://github.com/isaacs/npm/issues/2384, I'm submitting a duplicate. ]

When attempting to use the npm script under Cygwin in Windows, I receive the following error:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module 'H:\cygdrive\c\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js'
    at Function._resolveFilename (module.js:332:11)
    at Function._load (module.js:279:25)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

There are some cases where running in cmd.exe is not feasible (3rd party makefiles, e.g.). And we can do better: a simple change to the npm script to make it cygwin-aware will resolve this problem.

@ronin712

This comment has been minimized.

Show comment
Hide comment
@ronin712

ronin712 Jun 3, 2012

Here is an updated npm script that does the right thing under cygwin and should be POSIX compatible. Tested on cygwin/Windows and on OS X.

#!/bin/sh

NODE_DIR=`dirname "$0"`
case `uname` in
    *CYGWIN*) NODE_DIR=`cygpath -w "$NODE_DIR"`;;
esac

if [ -x "`dirname "$0"`/node.exe" ]; then
  "`dirname "$0"`/node.exe" "$NODE_DIR/node_modules/npm/bin/npm-cli.js" "$@"
else
  node "$NODE_DIR/node_modules/npm/bin/npm-cli.js" "$@"
fi

ronin712 commented Jun 3, 2012

Here is an updated npm script that does the right thing under cygwin and should be POSIX compatible. Tested on cygwin/Windows and on OS X.

#!/bin/sh

NODE_DIR=`dirname "$0"`
case `uname` in
    *CYGWIN*) NODE_DIR=`cygpath -w "$NODE_DIR"`;;
esac

if [ -x "`dirname "$0"`/node.exe" ]; then
  "`dirname "$0"`/node.exe" "$NODE_DIR/node_modules/npm/bin/npm-cli.js" "$@"
else
  node "$NODE_DIR/node_modules/npm/bin/npm-cli.js" "$@"
fi
@isaacs

This comment has been minimized.

Show comment
Hide comment
@isaacs

isaacs Jun 4, 2012

Member

Cygwin is not supported. Please use the windows native build with cmd, powershell, or msys git bash.

Member

isaacs commented Jun 4, 2012

Cygwin is not supported. Please use the windows native build with cmd, powershell, or msys git bash.

@isaacs isaacs closed this Jun 4, 2012

@TyOverby

This comment has been minimized.

Show comment
Hide comment
@TyOverby

TyOverby Jun 6, 2012

May I ask why cygwin isn't supported? I don't know anyone that uses cmd or powershell. Git bash is great, but Cygwin is, for many, the default programming environment.

TyOverby commented Jun 6, 2012

May I ask why cygwin isn't supported? I don't know anyone that uses cmd or powershell. Git bash is great, but Cygwin is, for many, the default programming environment.

@isaacs

This comment has been minimized.

Show comment
Hide comment
@isaacs

isaacs Jun 6, 2012

Member

@TyOverby Cygwin is pretty terrible if your program does a lot with child processes and low-level filesystem IO. That rant is best saved for some time in person with a few drinks. Node never worked well under Cygwin, and npm was worse. It's much faster and more stable to go direct to the OS.

Member

isaacs commented Jun 6, 2012

@TyOverby Cygwin is pretty terrible if your program does a lot with child processes and low-level filesystem IO. That rant is best saved for some time in person with a few drinks. Node never worked well under Cygwin, and npm was worse. It's much faster and more stable to go direct to the OS.

@TyOverby

This comment has been minimized.

Show comment
Hide comment
@TyOverby

TyOverby Jun 6, 2012

Fair enough. Not what I wanted to hear, but if performance is the reason, I'm all for it.

TyOverby commented Jun 6, 2012

Fair enough. Not what I wanted to hear, but if performance is the reason, I'm all for it.

@isaacs

This comment has been minimized.

Show comment
Hide comment
@isaacs

isaacs Jun 6, 2012

Member

We could probably get decent performance, but it's just not worth the work it would take to get there.

Member

isaacs commented Jun 6, 2012

We could probably get decent performance, but it's just not worth the work it would take to get there.

@pkhpkh

This comment has been minimized.

Show comment
Hide comment
@pkhpkh

pkhpkh Jun 6, 2012

Contributor

This issue is specifically asking for support for invoking the
Windows-compiled node.exe in a Cygwin environment, though. All of the
process and file system calls will still go to the OS, so I don't see
how the performance issue is a concern here.

Unless it's a slippery slope thing and a blanket "no cygwin" response
is just easier. (Which, to be clear, seems perfectly reasonable to
me.)

.

Contributor

pkhpkh commented Jun 6, 2012

This issue is specifically asking for support for invoking the
Windows-compiled node.exe in a Cygwin environment, though. All of the
process and file system calls will still go to the OS, so I don't see
how the performance issue is a concern here.

Unless it's a slippery slope thing and a blanket "no cygwin" response
is just easier. (Which, to be clear, seems perfectly reasonable to
me.)

.

@TyOverby

This comment has been minimized.

Show comment
Hide comment
@TyOverby

TyOverby Jun 6, 2012

Yeah, the only problem that I was having with it on cygwin was that npm was trying to look for modules in the wrong (cygwin only) directory. (Node itself worked just fine)

TyOverby commented Jun 6, 2012

Yeah, the only problem that I was having with it on cygwin was that npm was trying to look for modules in the wrong (cygwin only) directory. (Node itself worked just fine)

@isaacs

This comment has been minimized.

Show comment
Hide comment
@isaacs

isaacs Jun 6, 2012

Member

Path issues are about 90% of the pain of getting something to work on windows. The performance of node.exe is much better than the cygwin-compiled node binary, but it's still unnecessarily difficult to get everything working properly, since node and npm on windows assume that the paths will behave like windows paths.

This is not going to happen, sorry. It's not nearly valuable enough to justify the considerable cost.

Member

isaacs commented Jun 6, 2012

Path issues are about 90% of the pain of getting something to work on windows. The performance of node.exe is much better than the cygwin-compiled node binary, but it's still unnecessarily difficult to get everything working properly, since node and npm on windows assume that the paths will behave like windows paths.

This is not going to happen, sorry. It's not nearly valuable enough to justify the considerable cost.

@TyOverby

This comment has been minimized.

Show comment
Hide comment
@TyOverby

TyOverby Jun 6, 2012

I got it working fairly easily today, so I will just post this here in case anyone stumbled upon it from Google. The basic idea is that you create symlinks to the folders that node uses.

Often times, npm and node will look for c:/cygdrive/c/...... which doesn't exist because it is faked by cygwin. But what you can do is create the c:/cygdrive/c/ folder and then make symlinks inside of those.

Please note that you have to use the windows symlink function "MKLINK /D to from"

The symlinks that I created to get npm and CoffeeScript working were:

From To
C:\Program Files (x86)\nodejs C:\cygdrive\c\Program Files (x86)\nodejs
C:\Users C:\cygdrive\c\Users

This tricks npm and node into actually going to the right directory to look for these things.

I'm not sure if these are all of the paths that need to be symlinked and I'm also not sure if this will break anything, so use at your own risk.

Edit: If someone would provide me all of the paths that Node uses, I'd be happy to compile and write an installation script of some sort.

TyOverby commented Jun 6, 2012

I got it working fairly easily today, so I will just post this here in case anyone stumbled upon it from Google. The basic idea is that you create symlinks to the folders that node uses.

Often times, npm and node will look for c:/cygdrive/c/...... which doesn't exist because it is faked by cygwin. But what you can do is create the c:/cygdrive/c/ folder and then make symlinks inside of those.

Please note that you have to use the windows symlink function "MKLINK /D to from"

The symlinks that I created to get npm and CoffeeScript working were:

From To
C:\Program Files (x86)\nodejs C:\cygdrive\c\Program Files (x86)\nodejs
C:\Users C:\cygdrive\c\Users

This tricks npm and node into actually going to the right directory to look for these things.

I'm not sure if these are all of the paths that need to be symlinked and I'm also not sure if this will break anything, so use at your own risk.

Edit: If someone would provide me all of the paths that Node uses, I'd be happy to compile and write an installation script of some sort.

@katowulf

This comment has been minimized.

Show comment
Hide comment
@katowulf

katowulf Jun 9, 2012

@isaacs, for a lot of us it's not about what's terrible or great but simply a matter of calling npm install on the many dependencies needing Make.

The solutions seems to be Cygwin, ming-gw, or GnuWin.

Each of these presents its own list of incompatibilities and issues to correct, but Cygwin is a nearly perfect match, if that damned path just worked so I could get my package dependencies working without a fuss. : (

katowulf commented Jun 9, 2012

@isaacs, for a lot of us it's not about what's terrible or great but simply a matter of calling npm install on the many dependencies needing Make.

The solutions seems to be Cygwin, ming-gw, or GnuWin.

Each of these presents its own list of incompatibilities and issues to correct, but Cygwin is a nearly perfect match, if that damned path just worked so I could get my package dependencies working without a fuss. : (

@isaacs

This comment has been minimized.

Show comment
Hide comment
@isaacs

isaacs Jun 10, 2012

Member

I'd accept a small low-impact patch for this if someone wants to write it. It's just that I don't consider cygwin support relevant enough to spend time on. When you come to me complaining that Node and npm perform like crap on Cygwin and leave lots of orphaned processes, you'll have my sympathy, but also my "I told you so". It's awful.

Member

isaacs commented Jun 10, 2012

I'd accept a small low-impact patch for this if someone wants to write it. It's just that I don't consider cygwin support relevant enough to spend time on. When you come to me complaining that Node and npm perform like crap on Cygwin and leave lots of orphaned processes, you'll have my sympathy, but also my "I told you so". It's awful.

@pkhpkh

This comment has been minimized.

Show comment
Hide comment
@pkhpkh

pkhpkh Jun 10, 2012

Contributor

Small, low-impact patch submitted. I've been using it for the better part of a month without issue. Thanks for taking it.

Also: I'm using Cygwin, I'm used to everything performing like crap. Unfortunately, it's better than any alternative I've found when I'm stuck on Windows.

Contributor

pkhpkh commented Jun 10, 2012

Small, low-impact patch submitted. I've been using it for the better part of a month without issue. Thanks for taking it.

Also: I'm using Cygwin, I'm used to everything performing like crap. Unfortunately, it's better than any alternative I've found when I'm stuck on Windows.

pkhpkh added a commit to pkhpkh/npm that referenced this issue Jun 12, 2012

pkhpkh added a commit to pkhpkh/npm that referenced this issue Jun 12, 2012

isaacs added a commit to nodejs/node-v0.x-archive that referenced this issue Jun 19, 2012

2012.06.19, Version 0.7.12 (unstable)
* npm: Upgrade to 1.1.29
- Improved 'npm init'
- Fix the 'cb never called' error from 'oudated' and 'update'
- Add --save-bundle|-B config
- Fix npm/npm#2465: Make npm script and windows shims cygwin-aware
- Fix npm/npm#2452 Use --save(-dev|-optional) in npm rm
- `logstream` option to replace removed `logfd` (Rod Vagg)
- Read default descriptions from README.md files

* Shims to support deprecated ev_* and eio_* methods (Ben Noordhuis)

* #3118 net.Socket: Delay pause/resume until after connect (isaacs)

* #3465 Add ./configure --no-ifaddrs flag (isaacs)

* child_process: add .stdin stream to forks (Fedor Indutny)

* build: fix `make install DESTDIR=/path` (Ben Noordhuis)

* tls: fix off-by-one error in renegotiation check (Ben Noordhuis)

* crypto: Fix diffie-hellman key generation UTF-8 errors (Fedor Indutny)

* node: change the constructor name of process from EventEmitter to process (Andreas Madsen)

* net: Prevent property access throws during close (Reid Burke)

* querystring: improved speed and code cleanup (Felix Böhm)

* sunos: fix assertion errors breaking fs.watch() (Fedor Indutny)

* unix: stat: detect sub-second changes (Ben Noordhuis)

* add stat() based file watcher (Ben Noordhuis)

mmalecki pushed a commit to mmalecki/npm that referenced this issue Jun 19, 2012

isaacs added a commit to nodejs/node-v0.x-archive that referenced this issue Jun 19, 2012

2012.06.19, Version 0.7.12 (unstable)
* npm: Upgrade to 1.1.30
  - Improved 'npm init'
  - Fix the 'cb never called' error from 'oudated' and 'update'
  - Add --save-bundle|-B config
  - Fix npm/npm#2465: Make npm script and windows shims cygwin-aware
  - Fix npm/npm#2452 Use --save(-dev|-optional) in npm rm
  - `logstream` option to replace removed `logfd` (Rod Vagg)
  - Read default descriptions from README.md files

* Shims to support deprecated ev_* and eio_* methods (Ben Noordhuis)

* #3118 net.Socket: Delay pause/resume until after connect (isaacs)

* #3465 Add ./configure --no-ifaddrs flag (isaacs)

* child_process: add .stdin stream to forks (Fedor Indutny)

* build: fix `make install DESTDIR=/path` (Ben Noordhuis)

* tls: fix off-by-one error in renegotiation check (Ben Noordhuis)

* crypto: Fix diffie-hellman key generation UTF-8 errors (Fedor Indutny)

* node: change the constructor name of process from EventEmitter to process (Andreas Madsen)

* net: Prevent property access throws during close (Reid Burke)

* querystring: improved speed and code cleanup (Felix Böhm)

* sunos: fix assertion errors breaking fs.watch() (Fedor Indutny)

* unix: stat: detect sub-second changes (Ben Noordhuis)

* add stat() based file watcher (Ben Noordhuis)
@gbakernet

This comment has been minimized.

Show comment
Hide comment
@gbakernet

gbakernet Jul 10, 2012

Thank you for this.

Thank you for this.

@hatelove85911

This comment has been minimized.

Show comment
Hide comment
@hatelove85911

hatelove85911 Apr 2, 2015

TyOverby's symbolic link solution works great, thanks

TyOverby's symbolic link solution works great, thanks

@chrisVillanueva

This comment has been minimized.

Show comment
Hide comment
@chrisVillanueva

chrisVillanueva Apr 29, 2015

I found that if you use "Cygwin.bat" to launch a terminal, you can run "npm init" and other commands with no issues. I made a shortcut to "C:\cygwin64\Cygwin.bat" and use that to launch terminal on Win8 Enterprise. If I launch cygwin terminal from anywhere else, some commands fail.

I found that if you use "Cygwin.bat" to launch a terminal, you can run "npm init" and other commands with no issues. I made a shortcut to "C:\cygwin64\Cygwin.bat" and use that to launch terminal on Win8 Enterprise. If I launch cygwin terminal from anywhere else, some commands fail.

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