2016-04-13 6 views
2

Practiceのbook.jsから簡単なスクリプトを実行しようとすると、次のエラーが発生します。node.jsで「継承」エラーが発生するv5.10.1

このエラーの原因はわかりません。私は説明を見つけることができる最高の周りを捜したが、私はできなかった。 util.inheritモジュールはv5.10.1では動作しませんか?あるいは私は何か他のものを逃していますか私はnode.jsが初めてです。

~/node-project$ node index.js 
util.js:786 
    throw new TypeError('The super constructor to `inherits` must not ' + 
    ^

TypeError: The super constructor to `inherits` must not be null or undefined. 
    at Object.exports.inherits (util.js:786:11) 
    at Object.<anonymous> (/Users/byoungdale/node-project/countstream.js:6:6) 
    at Module._compile (module.js:413:34) 
    at Object.Module._extensions..js (module.js:422:10) 
    at Module.load (module.js:357:32) 
    at Function.Module._load (module.js:314:12) 
    at Module.require (module.js:367:17) 
    at require (internal/module.js:16:19) 
    at Object.<anonymous> (/Users/byoungdale/node-project/index.js:1:81) 
    at Module._compile (module.js:413:34) 

index.js

var CountStream = require('./countstream.js'); 
var countStream = new CountStream('book'); 
var http = require('http'); 

http.get('http://www.manning.com', function(res) { 
    res.pipe(countStream); 
}); 

countStream.on('total', function(count) { 
console.log('Total matches: ', count) 
}); 

countstream.js

var Writable = require('stream').Writeable; 
var util = require('util'); 

module.exports = CountStream; 

util.inherits(CountStream, Writable); 

function CountStream(matchText,options) { 
    Writeable.call(this, options); 
    this.count = 0; 
    this.matcher = new RegExp(matchText, 'ig'); 
} 

CountStream.prototype._write = function(chunk, encoding, cb) { 
    var matches = chuck.toString().match(this.matcher); 
    if (matches) { 
    this.count += matches.length; 
    } 
    cb(); 
}; 

CountStream.prototype.end = function() { 
    this.emit('total', this.count); 
}; 
+4

'Writeable'は' Writable'でなければなりません。 (いくつかのグーグルでは、過去に「書き込み可能」で使用されていたモジュールのように見えますが、それ以上はありません)。 –

+3

エラーは 'Writable'が未定義であることを意味します。' inherits'はいつものように動作します。 – Bergi

答えて

0

あなたはこれを試すことができます。これはあなたのために動作する場合。

var Writeable = require( 'stream')。書き込み可能。

関連する問題