9

我尝试安装 jsdom 这样的:

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

在一些成功的命令之后,安装很快就会失败,第一条错误消息在[....]

$ 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
....

暗示?其他模块也会出现此错误:

 $sudo npm install -g topojson 
 #bug with `contextify@0.1.7 install` error as well.

在此处输入图像描述

如何解决?


编辑:我尝试sudo apt-get remove --purge nodejs npm topojson通过各种方式重新安装。即使nodejs重新安装成功,错误仍然存​​在,所以我猜它是上​​下文相关的(node.gyp??cwd...)。尝试删除/重新安装方式:

4

3 回答 3

10

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.

于 2014-05-04T00:36:02.163 回答
3

似乎我通过仔细删除计算机上所有与节点相关的文件和文件夹找到了一种方法。

0. 上下文:我之前做了几次不成功的控制台清理,有

sudo apt-get remove --purge nodejs npm topojson

其次是〜3种不同的重新安装方式nodejs。我尝试了每种方法,从清理到重新安装,在 2 到 4 次之间。

1. 终端清除:让我们首先以最深的方式清理我的烂摊子:

npm cache clean; bower cache clean; grunt clean;
sudo apt-get remove --purge nodejs npm topojson

然而,我只是注意到这种深度清除不会清除/删除已安装的节点模块,这些模块会保持不变。

2. 手动清洗:另外,我用手动清洗进一步推动了清洗nodejsnode_modules。我在计算机上查找所有相关文件夹,越靠近根目录 (ubuntu: /home/<user>/) 越好。我小心地删除了所有以前安装的全局.../node-modules/文件夹,而不删除本地模块(特定的本地安装,它们仍在工作)。

3.重新安装:然后以下控制台允许重新安装:

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

之后,我通过 npm 模块topojson(取决于自身jsdom)进行的文件转换工作正常:

cd /myfolder/
topojson -o output.topo.json input.geo.json   

4.结论:我无法确定原因,哪个文件/文件夹删除允许成功sudo apt-get install nodejs+sudo npm install -g topojson重新安装。但是通过鼠标和递归删除进行的深度清理sudo rm -r [node related folder/file]最终解决了我的情况。

/!\对递归删除要非常小心。/!\rm -r

于 2014-05-05T13:47:20.363 回答
0

解决方案 1b:我 [怀疑][1] 是rm -r /home/<user>/local/lib/node_modules/解锁情况的关键因素。您可以列出全局(-g)节点模块,然后专门删除相关的(topojson和/或jsdom和/或node-gyp),然后重新安装它(它们)。

命令:在 ubuntu 上,尝试...

 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

注意:topojson取决于jsdomnpm-gyp

[1]:没有尝试过,但根据我的诊断是有道理的。

于 2014-05-06T19:36:40.090 回答