my tale of npm woe – when all else fails, fix your path!

To end the year I decided to look at Node.js and, in particular, the restify module. Things went south pretty quickly when npm install failed for restify with the following error (fragment):

npm ERR! git clone git://github.com/pvorb/node-clone.git CreateProcessW: The
system cannot find the file specified.
npm ERR! git clone git://github.com/davepacheco/node-verror.git
CreateProcessW:
The system cannot find the file specified.
npm ERR! Error: `git “clone” “git://github.com/pvorb/node-clone.git”
“C:\\Users\\Neil\\AppData\\Local\\Temp\\npm-704\\1357013683090-0.8436955371871591″`
failed with 127
npm ERR! at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\exec.js:56:20)

I reinstalled Node on the PC and tried again with no more success. I used another PC and again met failure. This surprised me because I had successfully installed restify a few weeks ago.

A web search quickly brought me to a Glenn Block (@gblock)  post with a similar seeming error when he installed restify (and apologies to Glenn for stealing his title). Glenn solved his problem by cleaning out the npm cache. I tried this using:

npm cache clean

and watched the cache vanish from %appdata%\npm-cache. Alas, unlike Glenn’s, my tale of npm woe continued since this didn’t solve the problem.

Another search led me to this post on the Windows Azure forums with the title npm fails on git dependencies in package.json. The latest version of restify has two git dependencies in its package.json – and they seem to be the source of the problem since tweaking the restify package,json for restify to handle git download for them allows git install to complete successfully for that package.

This is not really a satisfactory solution but a careful reading of the forum post leads to the solution. Amit Apple (@amitapl) Amit writes: the part that’s failing is to find git.exe since you’re using a git url to install the npm package.

It’s hard from the original error message to detect that git.exe is the problem – as, indeed, it is. Although git.cmd was in the path git.exe was not – causing the download to fail since npm looked for git.exe. Fixing the path fixed my npm problem – woohoo.

And so my tale of npm woe ended. Now onto the new year and new problems.

About these ads

About Neil Mackenzie

Cloud Solutions Architect. Microsoft
This entry was posted in Node.js and tagged , . Bookmark the permalink.

7 Responses to my tale of npm woe – when all else fails, fix your path!

  1. Glenn Block says:

    Nice post Neil

    We unfortunately hit this problem as well as recently we changed our release branch for our azure-cli github repo to point to the dev branch for the azure-sdk-for-node in package.json and we did the same thing for our release branch. We needed to do this as the cli may depend on unreleased sdk features.

    Anyway, some of our partners got hit with this because we didn’t realize it needed git. In most cases it was because they install git using git-bash only so it was not in their path.

    However, it turns out you can avoid this problem altogether by not using git urls, and instead using the HTTP tarball url. The url for our sdk for example in the dev branch is http://github.com/windowsazure/azure-sdk-for-node/tarball/dev. npm supports downloading tarballs directly, so this will work without a git client.

    Now if you are using a module that depends on a git repo you might still be out of look. However even in that case if you generate an npm-shrinkwrap.json file (npm shrinkwrap) you can then modify the generated json file to use HTTP urls.

    Happy New Year!

  2. Here’s the node bug for this: https://github.com/joyent/node/issues/2318

    It’s somewhere near the bottom of my todo list to fix this (libuv patch). But Glenn, if your team has resources for this it’d be a big help for Windows devs.

  3. @Domenic – thanks for pointing out the general nature of this problem. I notice now that you even provide the fix I used in the following npm open issue:

    https://github.com/isaacs/npm/issues/2644

    @Glenn – thanks for adding the extra detail. This is essentially the hack I did where I alluded to tweaking the package.json for restify. The problem is that these are second level dependencies which made it a little too complicated and not really generalizable (not to mention my lack of expertize). npm install on the restify tarball itself fails for the same reason. Given the push to get more people using Node.js on Windows and the likelihood of others hitting the same problem it would be great if, as Domenic suggests, we could get a fix for the underlying problem.

    • I think the issue is what you select at GIT install time. When you use the GIT installer it prompts you for How GIT tools should integrate. If you select GIT bash only it won’t be in your path. When I installed, I had it set to full integrate. If you do that it puts GIT in your path and does work.

  4. Interesting, you are saying this bug is related to PATHEXT? I don’t think GIT installer is using that as if it was it wouldn’t work by default on my machine.

  5. Jeff says:

    all i did was install git and it worked

  6. You are a life saver. I didn’t even know there was a git.cmd.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s