Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building d3.js on Windows (Cygwin) - good workaround for 'npm install' path issue?

Tags:

npm

cygwin

d3.js

I am trying to build d3.js under Windows. I have installed cygwin to run the makefile. However, as part of make install, it calls 'npm install', and this call fails:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
 Error: Cannot find module 'C:\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)

Makefile:230: recipe for target `install' failed
make: *** [install] Error 1

The problems seems to be that the cygwin path prefix ('cygdrive\c') is added to the file path (other than that, the path is correct).

I am wondering if there is a good workaround for this problem? I have tried to export the NODE_PATH variable as well as changing it in the Makefile. However, this does not affect this error (and I would prefer to keep the Makefile as it is).

EDIT: It worked when I called 'npm install' from the Webstorm command line (without cygwin). I had to install contextify (jsdom requirement) manually ('npm install contextify -f' and then copy the .node file from https://github.com/Benvie/contextify/downloads into build/Release for contextify), and to run 'npm install jsdom' and 'npm install vows' afterwards.

like image 686
Lars Grammel Avatar asked Mar 01 '12 03:03

Lars Grammel


2 Answers

You can edit the npm script so that it is cygwin-aware:

#!/bin/sh
cygwin=false;
case "`uname`" in
  CYGWIN*) cygwin=true;
esac

basedir=`dirname "$0"`

if $cygwin; then
    basedir=`cygpath -w "$basedir"`
fi

if [ -x "`dirname "$0"`/node.exe" ]; then
  "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
else
  node "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
fi
like image 120
2 revs Avatar answered Nov 18 '22 15:11

2 revs


I don't have a CYGWIN environment variable so pkh's answer didn't work for me, but changing the npm script (by default in C:\Program Files\nodejs) like this should work for all cygwin environments.

#!/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

If you're at a cygwin bash prompt, you can also run npm.cmd instead of npm if you don't want to edit the script.

like image 20
ronin Avatar answered Nov 18 '22 13:11

ronin