通过node.js v5.10.1获取“inheritance”错误

尝试从Node.js实践中运行一个简单的脚本时出现以下错误。

我不知道是什么原因造成这个错误。 我search了最好的,我可以find一个解释,但我不能。 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); }; 

你可以试试这个 如果这可能适合你。

var Writeable = require('stream')。可写;