2013-03-12 34 views
3

財產 '原型' app.jsutil.inherits引發TypeError:無法讀取的不確定

var Website = new require('./jslib/website.js'); 

./jslib/website.js

var util = require('util'), 
    events = require('events'); 

module.exports = Website; 
function Website() 
{ 
    events.EventEmitter.call(this); 
    return this; 
} 
util.inherits(Website, events.EventEmiter); 

控制檯輸出

PATH_TO_APPDIR>node app.js 

util.js:538 
    ctor.prototype = Object.create(superCtor.prototype, { 
             ^
TypeError: Cannot read property 'prototype' of undefined 
    at Object.exports.inherits (util.js:538:43) 
    at Object.<anonymous> (PATH_TO_APPDIR\jslib\website.js:9:6) 
    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 new require (module.js:378:17) 
    at Object.<anonymous> (PATH_TO_APPDIR\app.js:1:16) 
    at Module._compile (module.js:449:26) 

這是Windows 7上的NodeJS 8.22 *

+1

感謝您的提醒 – HyderA 2015-11-08 05:57:24

回答

9

您在代碼中存在拼寫錯誤。

util.inherits(Website, events.EventEmiter); 

應該

util.inherits(Website, events.EventEmitter); 
+1

神該死......! – HyderA 2013-03-12 06:40:42

+1

第一個Google搜索結果:node events無法讀取undefined的屬性'prototype'我也因爲輸入錯誤而變得瘋狂。我寫道:'EventEmmiter'。順便說一句:爲什麼不接受這個答案? – Peter 2013-03-22 11:18:15