コマンドラインから以下のスクリプトを実行しようとしています
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);
}); //script.js
コマンドは$ node script.js page.html
どこpage.html
にありますか引数は
私が得るエラーは次のとおりです。
./node_modules/jquery/dist/jquery.js:29
throw new Error( "jQuery requires a window with a document" );
Error: jQuery requires a window with a document
at module.exports (./node_modules/jquery/dist/jquery.js:29:12)
...
私はjquery-2.1.3を使用しています。これはかつては機能していたことは知っていますが、何かが変わったようです。
また、http://rkulla.blogspot.com/2014/04/using-browserify-with-jquery-backbonejs.htmlの指示に従いましたが、それでも同じエラーが発生します。
このエラーを修正するための助けをいただければ幸いです。どうもありがとうございました!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加