Npm install <module> permanent error? (node ββ-gyp build?)
I am trying to install jsdom, for example:
$ sudo npm install -g jsdom # OR $ sudo npm install jsdom After some successful command, the installation will quickly fail, the first error message after [....] :
$ sudo npm install jsdom npm http GET https://registry.npmjs.org/jsdom npm http 304 https://registry.npmjs.org/jsdom [....] > contextify@0.1.7 install /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify > node-gyp rebuild gyp: /home/yug/.node-gyp/0.10.25/common.gypi not found (cwd: /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify) while reading includes of binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:337:16) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12) gyp ERR! System Linux 3.8.0-35-generic gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test/node_modules/jsdom/node_modules/contextify gyp ERR! node -v v0.10.25 gyp ERR! node-gyp -v v0.12.2 gyp ERR! not ok npm http 304 https://registry.npmjs.org/domhandler npm http 304 https://registry.npmjs.org/domelementtype npm ERR! contextify@0.1.7 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the contextify@0.1.7 install script. npm ERR! This is most likely a problem with the contextify package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls contextify npm ERR! There is likely additional logging output above. npm ERR! System Linux 3.8.0-35-generic npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "jsdom" npm ERR! cwd /home/yug/Desktop/QGis/WikiAtlas/1_shaded_relief/test npm ERR! node -v v0.10.25 npm ERR! npm -v 1.3.24 npm ERR! code ELIFECYCLE npm http 304 https://registry.npmjs.org/qs npm http 304 https://registry.npmjs.org/entities .... Hint? This error also appears for other modules:
$sudo npm install -g topojson #bug with `contextify@0.1.7 install` error as well. 
How to fix it?
Edit: I tried sudo apt-get remove --purge nodejs npm topojson and then reinstalled it in various ways. Even if nodejs reinstalled successfully, the error remains , so I assume it is quite contextual ( node.gyp ? cwd ? ...). Remove / reinstall the verified paths:
- ubuntu_setup.sh
- with legacy legacy URL
- from URL updated to https://github.com/joyent/node.git ,
sudo add-apt-repository ppa:chris-lea/node.js,- and handmade
git clone https://github.com/joyent/node.git(trial version canceled) - using various other methods :
- way1: ogoing
I seem to have found a way by carefully deleting all node related files and folders on my computer.
0. Context: I previously did some unsuccessful console cleanups,
sudo apt-get remove --purge nodejs npm topojson and then ~ 3 different ways to reinstall nodejs . I tried EVERY way, from cleaning to reinstalling, between 2 and 4 times.
1. Cleaning the terminal: Let me first clear my mess in the deepest way:
npm cache clean; bower cache clean; grunt clean; sudo apt-get remove --purge nodejs npm topojson However, I just noticed that this deep cleanup does NOT remove / remove installed node modules that remain constant.
2. Manual cleaning:. In addition, I pressed purge again using manual purge for both nodejs and node_modules . I searched ALL ALL the related folders on my computer, the closer to the root (ubuntu: /home/<user>/ ), the better. I tried to remove all previously installed global folders .../node-modules/ without deleting local modules (certain local settings that still work).
3. Reinstall:. Then the following consoles allowed a clean reinstall:
sudo apt-get update sudo apt-get install python-software-properties python g++ make sudo add-apt-repository ppa:chris-lea/node.js sudo apt-get update sudo apt-get install nodejs sudo npm install -g topojson jsdom After that, my file conversion through the npm topojson module (depending on jsdom ) worked fine:
cd /myfolder/ topojson -o output.topo.json input.geo.json 4. Conclusion: I canβt determine the reason why deleting the file / folder allows the successful installation of sudo apt-get install nodejs + sudo npm install -g topojson . But Thist deep mouse cleaning and recursive removal of sudo rm -r [node related folder/file] finally unlocked my situation.
/! \ Be very careful with rm -r recursive deletion ./! \
As you learn from the comments, this is a very common problem. In fact, it is so common that jsdom authors documented it in a README file for the git project repository.
TL; DR
To install contextify , on which the jsdom dependency is installed, C ++ and Python2.7 compiler must be installed on your computer. Otherwise, the jsdom installation will fail.
From README on the Github page for jsdom :
Contextify
Context is a jsdom dependency used to run
<script>tags on a page. In other words, it allows jsdom, which runs in Node.js, to run JavaScript strings in an isolated environment that claims to be the browser environment instead of the server. You can see how this is an important feature.Unfortunately, such magic requires C ++. And in Node.js, using C ++ from JavaScript, use the "native modules". Native modules were compiled during installation so that they work specifically for your machine; that is, you are not downloading the contextify binary from npm, but instead creating one locally after loading the source from npm.
Unfortunately, getting C ++ compiled in the npm installation system can be difficult, especially for Windows users. Thus, one of the most common problems with jsdom is trying to use it without compilation tools installed. Here is what you need to compile Contextify and therefore to install jsdom:
Window
- The latest x86 version of Node.js for Windows, not the x64 version.
- Copy of Visual C ++ 2010 Express.
- A copy of Python 2.7 installed at the default location C: \ Python27.
There are some minor changes to this that may work; for example, full versions of Visual Studio usually work, and sometimes you can even use the x64 version of Node.js. But itβs difficult, so start with the basics!
Mac
- You must install Xcode.
- "Command line tools for Xcode" must be installed
- Launch Xcode once to accept the license, etc. and make sure it is installed correctly
Linux
You will need various build tools such as make, Python 2.7, and the toolchain compiler. How to install them will be specific to your distribution, if not already.
Try installing jsdom again after satisfying the requirements mentioned above for your OS, and see if that permits.
By the way, you get the same problem with topojson , because it has a dependency on d3 , which in turn depends on jsdom , so this is just a problem installing jsdom. Hope this helps!
- EDIT -
Since it seems that you are using Ubuntu, I would recommend starting with the following command:
sudo apt-get install build-essential This will install make and g ++ and some other tools. This package and Python2.7 are probably about everything you need to successfully set the context.
Solution 1b: I [suspect] [1] the rm -r /home/<user>/local/lib/node_modules/ will be the key element to open the situation. You can specify global ( -g ) node_modules, and then delete the corresponding objects ( topojson and / or jsdom and / or node-gyp ) and then reinstall them (them).
Commands: On ubuntu try ...
cd /home/<user>/local/lib/node_modules/ #replace <user> by relevant user name to set your cwd ls -1 # give the list of global modules names rm -r /<module_name> #replace <module_name> by relevant name to remove it sudo npm install -g <module_name> #replace <module_name> by relevant name for global install Note: topojson depends on jsdom and npm-gyp .
[1]: I have not tried it, but it makes sense in accordance with my diagnosis.