安装NodeJS contextify包会产生错误

我是1个小时进入NodeJS,所以忍受着我。 我的项目需要的一个包是JSDom。 在刺激了大部分互联网之后,我发现JSDOm有一个名为contextify的依赖关系,这在某种程度上是在JSDom安装本身内部处理的。 所以这就是我所做的:

sudo npm install jsdom 

一切顺利,直到我得到以下几点:

 gyp WARN install got an error, rolling back install gyp ERR! rebuild error Error: EACCES, stat '/root/.node-gyp/0.8.2' gyp ERR! not ok npm ERR! contextify@0.1.7 install: `node-gyp rebuild` npm ERR! `sh "-c" "node-gyp rebuild"` failed with 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.2.0-60-generic npm ERR! command "/opt/node/bin/node" "/opt/node/bin/npm" "install" "contextify" npm ERR! cwd /opt/node npm ERR! node -v v0.8.2 npm ERR! npm -v 1.1.36 npm ERR! code ELIFECYCLE npm ERR! message contextify@0.1.7 install: `node-gyp rebuild` npm ERR! message `sh "-c" "node-gyp rebuild"` failed with 1 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /opt/node/npm-debug.log npm ERR! not ok code 0 

难倒!

我发现为了在Ubuntu上运行,我必须要make,python和G ++。 我拥有他们。 那么我到底错过了什么呢?

仅供参考,JSDOM安装尝试之前的命令是:

 mkdir ~/.node-gyp chmod -R 777 ~/.node-gyp 

我也尝试了以下几点:

 npm install -g node-gyp npm install contextify 

在第二个命令,我遇到了同样的问题。

你可能需要这样做

sudo npm install -g npm

并再试一次(它在我的Mac上工作)

或者看到这个错误安装contextify-node-gyp重build失败

如果你在节点上做了一个标准的apt-get,它可能会落后于时代,而采用最新的bundle release可能会解决这个问题

情况发生了变化: jsdom >= 4.0.0不再使用contextify :

4.0.0

这个版本依赖于io.js的新大小的vm模块来消除Contextify本地模块依赖。 jsdom现在应该更容易使用和安装,而不需要C ++编译器工具链!

而如果你需要一个没有争议的老人,试试jsdom-no-contextify 。

node-gyp EACCES可以通过更改访问权限来解决,有时也可以按如下方式设置npm的node-gyp python版本:

 sudo chown -R $USER /usr/local 

 npm config set python /usr/bin/python2.7 

(根据与哪个版本相关,将python2.6更改为python2.6