當我初始化應用程序一切都很好,但當我去任何頁面 像「本地主機/」我得到這個(雙:索引一次.html和一次請求的JavaScript,參見下文)錯誤:「undefined不是函數」錯誤,當使用貓鼬會話和快速
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
這是我使用的代碼:
var express = require('express');
var app = this.__app = express();
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
store: this.__getSessionStore()
,secret: this.__secretSession
}));
app.post('/rpc', this.__manageRequest.bind(this)); // <-- this method is not even called
app.use("/client", express.static('./client/')); //
// gets the index.html, but files in subfolders (which exists) throws the second error in the double error
app.use("/", express.static('./client/production/build'));
app.listen(this.__appPort, this.__appIp);
我如何獲得會話存儲:
__getSessionStore: function(){
var express = require('express');
var app = this.__app;
var SessionMongoose = require("session-mongoose")(express);
var mongooseSessionStore = new SessionMongoose({
url: this.__mongodbUrl
,interval: 120000
});
return mongooseSessionStore;
}
個
快遞版本:3.0.0 貓鼬的會話版本:0.2.0
未定義的方法是「CRC16」在哈希方法:在調試未定義太
function hash(sess) {
return crc16(JSON.stringify(sess, function(key, val){
if ('cookie' != key) return val;
}));
}
在CRC模塊,有一個if(窗口)和窗口被定義,問題是我看不到它的定義在哪裏! 由於此窗口,它不會導出任何模塊,因此函數未定義!我只是非常黑客刪除if(窗口)始終導出到它的模塊。 那麼,這是[email protected]模塊(https://github.com/alexgorbatchev/node-crc/pull/10)中的一個錯誤,並且express需要確切的版本。
究竟是什麼問題,以及如何解決它? 非常感謝
好吧,當crc作者更新crc模塊,沒有改變版本,所以它仍然[email protected],但有一個不同的版本...所以必須刪除該文件夾,安裝crc ...或者,也許在git中的[email protected]與npm中的不同..不知道,因爲我直接從git複製。 –