Javascript 使用'获取错误;继承';使用node.js v5.10.1
在实践中尝试从book Node.js运行简单脚本时,我遇到以下错误 我不确定是什么导致了这个错误。我尽我所能寻找解释,但我找不到。util.inherit模块在v5.10.1中不工作吗?还是我错过了什么?我是node.js的新手Javascript 使用'获取错误;继承';使用node.js v5.10.1,javascript,node.js,Javascript,Node.js,在实践中尝试从book Node.js运行简单脚本时,我遇到以下错误 我不确定是什么导致了这个错误。我尽我所能寻找解释,但我找不到。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:
~/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)
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')。可写
可写的
应该是可写的
,而且你可能很好。(从一些谷歌搜索中,它看起来像是过去使用的一些模块,Writeable
,但现在不再使用了。)干杯。这个错误只是意味着Writeable
未定义-继承
一如既往地工作。
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);
};