NPM (Node-Package-Manager) Package Install Errors:
Misleading Error Messages
I recently found myself encountering some nearly useless NPM errors when I was trying to install the redis-node package (i.e., Redis.io database connectivity layer for Nodejs), and it did not instantly occur to me why I was seeing error messages during NPM's archive-unpacking operation, especially as the Node-Package-Manager was dumping out a list of errors that made little sense.Under Linux, NPM install was producing errors that implied I did not have permission to the tmp / temporary directory or directories the package was being unzipped/unpacked into for installation from (i.e., the temporary location the tarball / tar.gz file would be unpacked in). Under Windows, the same NPM install (under git-bash window) produced different errors that made it appear the downloaded .git package could not be unpacked for god knows what reason, all hidden in a massive error dump that had nothing to do with the REAL reason for the error.
Well, I figured out why the errors occurred (as detailed in this blog entry), and I also learned that this NPM software is a perfect example of what I consider a non-user-friendly interface in that it presents the user with all sorts of completely meaningless error messages in the event of very simple-to-detect issues. Bottom line: the node package manager is written by geeks, for geeks. This is not "enterprise grade" software by any means, as it does not have robust error-detection/traps/messages. In fact, the error-traps it does employ seem to mislead more than assist: this is simply poor design. (note: I give credit to ANY open-source effort like this though, and I understand why people focus on other functionality vs. "usability").
Node Package Manager Windows Behavior and NPM Error Messages due to using wrong .git file URL
I have been using Node (Nodejs) for "server-side javascript" development on a Windows 7 Pro x64 machine, with Node "installed" as simply the Node.exe download placed in a local directory of c:\nodeFrom within that directory (using the git-bash terminal window on Windows that was installed with the Git SCM tool version 1.7.7.x Windows .exe installer), I executed the following command:
c:\node>node ./npm install -g https://github.com/mranney/node_redis.git
...but, that produces the following error dump. Can you see why? It was all too clear to me a bit later...
c:\node>node ./npm install -g https://github.com/mranney/node_redis.git
npm ERR! couldn't unpack C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\tmp.tgz to C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents
npm ERR! Error: ENOENT, no such file or directory 'C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents\package\package.json'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "node" "c:\\node\\npm" "install" "-g" "https://github.com/mranney/node_redis.git"
npm ERR! cwd c:\node
npm ERR! node -v v0.6.3
npm ERR! npm -v 1.0.105
npm ERR! path C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents\package\package.json
npm ERR! code ENOENT
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\node\npm-debug.log
npm not ok
npm ERR! couldn't unpack C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\tmp.tgz to C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents
npm ERR! Error: ENOENT, no such file or directory 'C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents\package\package.json'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "node" "c:\\node\\npm" "install" "-g" "https://github.com/mranney/node_redis.git"
npm ERR! cwd c:\node
npm ERR! node -v v0.6.3
npm ERR! npm -v 1.0.105
npm ERR! path C:\TEMP\npm-1322598499268\1322598499268-0.7676450146827847\contents\package\package.json
npm ERR! code ENOENT
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\node\npm-debug.log
npm not ok
Notice the URL I mistakenly specified for the install package... THAT is what causes the error. Yes, something as simple as copying and pasting the incorrect URL from the project's github page will lead to this tragic error-dump.
This is where I went wrong:
...the default URL shown in that textbox on Github (image above) is for the HTTP version of the URL. I had accidentally copied that and pasted to my command prompt for my "npm install" command, where instead I needed to do this:
Now I could copy and paste the proper git:// prefixed URL address of the node_redis.git package that I wanted to install with NPM.
c:\node>node ./npm install -g git://github.com/mranney/node_redis.git
...which produces the simple one-line output as a result of a "successful" package install:
redis@0.7.1 c:\node\node_modules\redis
Ah, that is better!
Now, on to what this same issue presents like under Linux...
Node Package Manager Linux Behavior and NPM Error Messages due to using wrong .git file URL
I have been using Node (Nodejs) under OpenSuse 12.1 x64 KDE. When I first encountered this issue under Windows, I quickly jumped over to my Linux VMware virtual-machine to see if for some reason it was a Windows-implementation-only issue (since, Node and NPM have been more mainstream on Linux, and the NPM under Windows is considered "experimental" yet).This quick test under Linux helped me see the error in my ways quickly, since I encountered a similar mess of misleading error-messages spewing forth from the node-package-manager when I copied and pasted my npm install command to Linux and executed it:
~/node> node ./npm install -g https://github.com/mranney/node_redis.git
Yes, it failed similarly to the Windows NPM version, but with an error message (pasted here) that sure made it appear like the the "tar" (unpack) command failed for some inability to work with the temp .tgz file created as part of the install process...
npm ERR! Failed unpacking /tmp/npm-1322603639405/1322603639405-0.840085425414145/tmp.tgz
npm ERR! couldn't unpack /tmp/npm-1322603639405/1322603639405-0.840085425414145/tmp.tgz to /tmp/npm-1322603639405/1322603639405-0.840085425414145/contents
npm ERR! Error: `tar "-zmvxpf" "/tmp/npm-1322603639405/1322603639405-0.840085425414145/tmp.tgz" "-o"`
npm ERR! failed with 2
npm ERR! at ChildProcess.<anonymous> (/home/mike/node/npm/lib/utils/tar.js:217:20)
npm ERR! at ChildProcess.emit (events.js:70:17)
npm ERR! at maybeExit (child_process.js:359:16)
npm ERR! at Process.onexit (child_process.js:395:5)
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Linux 3.1.0-1.2-desktop
npm ERR! command "node" "/home/mike/node/npm" "install" "-g" "https://github.com/mranney/node_redis.git"
npm ERR! cwd /home/mike/node
npm ERR! node -v v0.6.2
npm ERR! npm -v 1.0.106
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/mike/node/npm-debug.log
npm not ok
Having performed successful node module installs with NPM under my Linux host already, I knew that I must be missing something obvious. And, without any help at all from those meaningless error messages, I finally saw that I pasted the "https://" address of the github node module address instead of the git:// version. Fixing this mistake, the module installed just fine under both Linux and Windows.
This revelation (about my mistaken "https" vs. "git" prefix), coupled with my frustration at misleading NPM error messages, led to the writing of this blog in case anyone else runs into this issue and gets misled by utterly meaningless error messages.
I hope someone working on the NPM (package manager for node) will eventually make time to implement proper condition-testing (and meaningful error-reporting) to test the format of command-line parameters as important as the actual package/module URL if the format makes such a tremendous difference in results. Had this software simply tested the URL for a valid format, and told me "sorry, you must use git:// prefix" or suggested another equally effective alternative, that would be ideal and would save myself, and surely others, from wasting time with misleading error messages.
No comments:
Post a Comment