Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install <module> persistent error ? (node-gyp build ?)

I try to install jsdom such:

$ sudo npm install -g jsdom
# OR
$ sudo npm install    jsdom

After some successfull command, the install quickly fails, with the first error message being after the [....] :

$ sudo npm install jsdom 
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
[....]

> [email protected] 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! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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 bug also appears for other modules :

 $sudo npm install -g topojson 
 #bug with `[email protected] install` error as well.

enter image description here

How to fix that ?


Edit: I tried sudo apt-get remove --purge nodejs npm topojson then reinstalling via various ways. Even when nodejs reinstall is successfull, the error stays, so I guess it's rather contextual (node.gyp ? cwd ? ...). Remove/reinstall ways tried :

  • ubuntu_setup.sh
    • with native outdated url
    • with 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 canceled)
  • using various other ways :
    • way1 : ogoing
like image 277
Hugolpz Avatar asked Apr 14 '14 06:04

Hugolpz


People also ask

What is npm install node-gyp?

node-gyp-build works similar to node-gyp build except that it will check if a build or prebuild is present before rebuilding your project. It's main intended use is as an npm install script and bindings loader for native modules that bundle prebuilds using prebuildify .

What is node-gyp build?

js native addon build tool. node-gyp is a cross-platform command-line tool written in Node. js for compiling native addon modules for Node. js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node.


1 Answers

As you're finding out from the comments, this is a very common issue. So common, in fact, that the authors of jsdom have documented it right in the README file for the project's git repository.


TL;DR

You need to have a C++ compiler and Python2.7 installed on your machine to install contextify which is a dependency of jsdom. Otherwise, the jsdom install will fail.


From the README on the Github page for jsdom:

Contextify

Contextify is a dependency of jsdom, used for running <script> tags within the page. In other words, it allows jsdom, which is run in Node.js, to run strings of JavaScript in an isolated environment that pretends to be a browser environment instead of a server. You can see how this is an important feature.

Unfortunately, doing this kind of magic requires C++. And in Node.js, using C++ from JavaScript means using "native modules." Native modules are compiled at installation time so that they work precisely for your machine; that is, you don't download a contextify binary from npm, but instead build one locally after downloading the source from npm.

Unfortunately, getting C++ compiled within npm's installation system can be tricky, especially for Windows users. Thus, one of the most common problems with jsdom is trying to use it without the proper compilation tools installed. Here's what you need to compile Contextify, and thus to install jsdom:

Windows

  • A recent copy of the x86 version of Node.js for Windows, not the x64 version.
  • A copy of Visual C++ 2010 Express.
  • A copy of Python 2.7, installed in the default location of C:\Python27.

There are some slight modifications to this that can work; for example full versions of Visual Studio usually work, and sometimes you can even get an x64 version of Node.js working too. But it's tricky, so start with the basics!

Mac

  • XCode needs to be installed
  • "Command line tools for XCode" need to be installed
  • Launch XCode once to accept the license, etc. and ensure it's properly installed

Linux

You'll need various build tools installed, like make, Python 2.7, and a compiler toolchain. How to install these will be specific to your distro, if you don't already have them.

Try installing jsdom again after satisfying the requirements mentioned above for your OS, and see if that solves it.

By the way, you are getting the same issue with topojson because it has a dependency on d3 which in turn depends on jsdom, so it is just the same problem installing jsdom. Hope this helps!

--EDIT--

Since it sounds like you're 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 is probably about all you'll need to successfully install contextify.

like image 147
jshanley Avatar answered Oct 06 '22 08:10

jshanley