[英]Keep getting error for browserless jquery in node
我正在嘗試運行節點腳本和html頁面,但我一直收到錯誤。 我試圖運行的腳本是:
node script.js page.html
script.js文件包含以下內容:
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有以下代碼:
<html>
<body>
<p>Apple</p>
<span>Unrelated</span>
<p>Orange</p>
<div>Steak</div>
<p>Banana</p>
</body>
</html>
我的packages.json文件內容如下:
{
"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和optimist模塊但是我一直收到以下錯誤:
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)
是什么導致了這個錯誤
jquery模塊不適用於Windows。
https://github.com/coolaj86/node-jquery#does-not-work-on-windows
對不起,我無法提供更多幫助。
順便說一下,你的代碼可以在我的Linux機器上運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.