不断收到错误的节点无浏览器的jQuery [英] Keep getting error for browserless jquery in node

查看:81
本文介绍了不断收到错误的节点无浏览器的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行节点脚本和HTML页面,但我不断收到一个错误。我试图运行的脚本是:

I am trying to run a node script and an html page but I keep getting an error. The script I am trying to run is:

node script.js page.html

该文件的script.js具有如下:

The script.js file has the following:

var argv = require('optimist').argv,
$ = require('jquery'),
fs = require('fs');

var file = argv._[0];

var html = fs.readFileSync(file, 'UTF-8');

 $(html).find('p').each(function(index) {
var content = $(this).html();

console.log('Paragraph ' + (index + 1) + ': ' + content);
});

我page.html即可具有以下code:

my page.html has the following code:

<html>
 <body>
  <p>Apple</p> 
  <span>Unrelated</span>
  <p>Orange</p>
  <div>Steak</div>
  <p>Banana</p>
 </body>
</html>

我packages.json文件内容如下:

my packages.json file reads as follows:

{
  "name": "paragraphs",
  "version": "1.0.0",
  "main": "script.js",
  "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },
  "dependencies": {
      "optimist": "0.3.4",
      "jquery": "1.7.3"
   },
   "author": "Joe LeBlanc",
   "license": "BSD"
}

我已经安装了jQuery和乐观的模块,但我不断收到以下错误:

I have the jquery and optimist modules installed but I keep getting the following error:

C:\Documents and Settings\Amen.Ra\Desktop\paragraphs\node_modules\jquery\lib\node-jquery.js:10
window.XMLHttpRequest.prototype.withCredentials = false;

TypeError: Cannot read property 'prototype' of undefined at create (C:\Documents and Settings\Amen.Ra\Desktop\paragraphs\node_modules\jquery\lib\node-jquery.js:10:26)
at C:\Documents and Settings\Amen.Ra\Desktop\paragraphs\node_modules\jquery\lib\node-jquery.js:9435:18
at Object.<anonymous> (C:\Documents and Settings\Amen.Ra\Desktop\paragraphs\node_modules\jquery\lib\node-jquery.js:9437:2)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (C:\Documents and Settings\Amen.Ra\Desktop\paragraphs\script.js:2:6)

什么是导致此错误

What is causing this error

推荐答案

jQuery的模块不带窗户的工作。

The jquery module does not work with windows.

https://github.com/coolaj86/node- jQuery的#不 - 不工作的窗口

我很抱歉,我不能提供更多的帮助。

I am sorry that I cannot be more helpful.

顺便说一句,你的code工作在我的Linux机器。

BTW, your code works on my Linux box.

这篇关于不断收到错误的节点无浏览器的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆