在尝试编译标准的"Hello World"示例[2]时,我尝试在Windows 7 + Node.js平台上使用node-gyp失败[3].注意:当尝试npm install contextifyw或没有"-g"时,node-gyp以类似的方式失败[3] ,因此这些可能是相关的问题.
组态:
参考文献:
[1] https://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup
[2] https://github.com/joyent/node/tree/master/test/addons/hello-world
[3]"hello world"[2]项目中的"node-gyp rebuild"产生以下2个错误:
.... node-gyp\0.10.24\deps\uv\include\win.h(8738):错误C2371:'SYSTEM_POWER_STATUS':重新定义; 不同的基本类型[...\build\test.vcxproj]
.... node-gyp\0.10.24\deps\uv\include\mswsock.h(27):致命错误C 1083:无法打开包含文件:'_mingw.h':没有这样的文件或目录[... \编译\ test.vcxproj]
以及2个警告:
.... node-gyp\0.10.24\deps\uv\include\win.h(13513):警告C4005:'UNALIGNED':宏重新定义[...\build\test.vcxproj]
.... node-gyp\0.10.24\deps\uv\include\mswsock.h(26):警告C4068:未知的编译指示[...\build\test.vcxproj]
完整的跟踪如下:
C:\sigma\node_modules\x>node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.12.2
gyp info using node@0.10.24 | win32 | x64
gyp info spawn …Run Code Online (Sandbox Code Playgroud) 编辑
我升级了节点并运行了"npm install -g contextify"看起来它安装得很好(没有错误),但输入"which contextify"什么都不返回.安装contextify时的消息:
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.6 install /usr/local/share/npm/lib/node_modules/contextify
> node-gyp rebuild
CXX(target) Release/obj.target/contextify/src/contextify.o
SOLINK_MODULE(target) Release/contextify.node
SOLINK_MODULE(target) Release/contextify.node: Finished
contextify@0.1.6 /usr/local/share/npm/lib/node_modules/contextify
??? bindings@1.1.1
Run Code Online (Sandbox Code Playgroud)
原版的
我在使用npm安装contextify时遇到问题:
npm install -g contextify
Run Code Online (Sandbox Code Playgroud)
并获取以下错误消息:
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.6 install /usr/local/share/npm/lib/node_modules/contextify
> node-gyp rebuild
CXX(target) Release/obj.target/contextify/src/contextify.o
SOLINK_MODULE(target) Release/contextify.node
SOLINK_MODULE(target) Release/contextify.node: Finished
/usr/local/Cellar/node/0.10.1/lib/node_modules/npm/bin/node-gyp-bin/node-gyp: line 2: …Run Code Online (Sandbox Code Playgroud) 我尝试安装jsdom这样:
$ sudo npm install -g jsdom
# OR
$ sudo npm install jsdom
Run Code Online (Sandbox Code Playgroud)
在一些成功的命令之后,安装很快就会失败,第一条错误消息在[....]:
$ 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 …Run Code Online (Sandbox Code Playgroud) 我想让jsdom工作:)
这是代码:
var jsdom = require("jsdom");
var request = require("request");
var fs = require('fs');
var jquery = fs.readFileSync("./jquery-1.7.2.js", 'utf-8');
request({ uri:'http://nodejs.org/dist/' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('HTTP request error... '+error);
}
jsdom.env({
html: body,
scripts: [
jquery
],
done: function(errors, window) {
console.log('done');
}
});
});
Run Code Online (Sandbox Code Playgroud)
这是错误:
jsdom.js:171
features = JSON.parse(JSON.stringify(window.document.implementation._fea
^
TypeError: Cannot read property 'implementation' of undefined
Run Code Online (Sandbox Code Playgroud)
我已经检查了是否提取了页面以及是否解析了jquery lib - 它们是.
我们可以看一下jsdom.js的实现:
[snip]
exports.env = exports.jsdom.env = function() {
[snip] …Run Code Online (Sandbox Code Playgroud) 我进入NodeJS 1小时,所以请耐心等待.我的项目需要的一个软件包是JSDom.在激发了大部分互联网之后,我发现JSDOm有一个名为contextify的依赖项,它本身在JSDom安装中处理.所以这就是我的意思:
sudo npm install jsdom
Run Code Online (Sandbox Code Playgroud)
一切顺利,直到我得到以下内容:
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 …Run Code Online (Sandbox Code Playgroud) 我有兴趣为一个项目做一些服务器端的DOM操作,所以我决定看看node.js,特别是在jsdom.我对node.js完全不熟悉,所以我的错误可能是显而易见的,但是我从来没有找到解决我问题的方法......
首先,我在本地运行Windows节点,并使用在线IDE cloud9
值得一提的是,因为我在安装最新的节点jsdom包(0.2.15)时遇到了麻烦,因为在Windows下无法编译所需的依赖性上下文(需要C++和Python,因为我发现npm不支持构建C++包) .所以我采取了两种替代方法:
我安装了一个不依赖于contextify的旧版本,即jsdom@0.2.1.这是我目前拥有的npm列表
??? jsdom@0.2.1
??? cssom@0.2.5
??? htmlparser@1.7.6
??? request@2.10.0
Run Code Online (Sandbox Code Playgroud)
当我试图运行从jsdom github repo cloud9 采取的简单测试脚本时返回此警告
The "sys" module is now called "util". It should have a similar
Run Code Online (Sandbox Code Playgroud)
我试图解决这个问题取代所有提到的sys到util,错误消失了......(仍然不太确定这是正确的事情,虽然......).所以,最后当我试图运行这个片段时
var jsdom = require("jsdom");
jsdom.env("http://nodejs.org/dist/", [
'http://code.jquery.com/jquery-1.5.min.js'
],
function(errors, window) {
console.log("there have been", window.$("a").length, "nodejs releases!");
});
Run Code Online (Sandbox Code Playgroud)
我发现了那个window.$ === undefined.试图在cloud9上运行节点v0.6.x和节点v0.4.x,在本地运行节点v0.8.7.
我尝试做的另一件事是安装最新的jsdom@0.2.15,从这里获得编译的上下文,安装绑定并将其添加到contextify/node_modules,因为contextify依赖于它.我根本无法使它工作=(没有浪费太多时间,因为它似乎是一种错误的方法,并且上下文不是最新的.
这是npm列表
??? jsdom@0.2.15
??? contextify@0.1.2
? ??? bindings@1.0.0
??? cssom@0.2.5
??? …Run Code Online (Sandbox Code Playgroud)这是我跑步时得到的 npm install contextify
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.3 install C:\node_modules\myfolder\node_modules\contextify
> node-gyp rebuild
C:\node_modules\myfolder\node_modules\contextify>node "C:\Program Files\nodejs\node_
modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebui
ld
python: can't open file 'C:\Users\Username\.node-gyp\0.8.16\tools\gyp\gyp': [Errn
o 2] No such file or directory
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 2
gyp ERR! stack at ChildProcess.onCpExit (C:\Program Files\nodejs\node_module
s\npm\node_modules\node-gyp\lib\configure.js:395:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack at Process._handle.onexit (child_process.js:678:10) …Run Code Online (Sandbox Code Playgroud) contextify ×7
node.js ×7
jsdom ×4
node-gyp ×4
npm ×3
cloud9-ide ×2
javascript ×2
jquery ×1
python ×1
topojson ×1
windows ×1