提问人:tecguy 提问时间:5/23/2022 最后编辑:tecguy 更新时间:5/28/2022 访问量:496
throw new TypeError(“期待一个函数,但得到了” + util.classString(fn));TypeError:需要一个函数,但得到了 [object Undefined]
throw new TypeError("expecting a function but got " + util.classString(fn)); TypeError: expecting a function but got [object Undefined]
问:
在运行 Express 服务器时,连接正确,MongoDB 连接正确,但我在节点模块中遇到了问题,如上所述。node app.js
完整日志粘贴如下:
throw new TypeError("expecting a function but got " + util.classString(fn));
^
TypeError: expecting a function but got [object Undefined]
at Function.Promise.promisify (D:\Project\DD-NODEJS\node_modules\bluebird\js\release\promisify.js:270:15)
at D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:155:56
at Array.forEach (<anonymous>)
at MongoStore.setCollection (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:154:67)
at MongoStore.handleNewConnectionAsync (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:120:18)
at NativeConnection.<anonymous> (D:\Project\DD-NODEJS\node_modules\connect-mongo\src\index.js:91:72)
at Object.onceWrapper (node:events:509:28)
at NativeConnection.emit (node:events:402:35)
at NativeConnection.Connection.onOpen (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:647:8)
at _setClient (D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:895:8)
at D:\Project\DD-NODEJS\node_modules\mongoose\lib\connection.js:797:7
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\utils.js:423:9
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\mongo_client.js:130:17 at connectCallback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:29:9)
at D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\operations\connect.js:80:9
at Object.callback (D:\Project\DD-NODEJS\node_modules\mongoose\node_modules\mongodb\lib\sdam\topology.js:230:17)
答:
1赞
Rishabh Kumar Mayank
5/28/2022
#1
嗨,在nodejs中连接MongoDB会话时遇到了类似的问题。
修复步骤:
更新 mongoose 和 connect-mongo 程序包。
更新 require 语句。从中删除(会话)。 const MongoStore = require('连接-mongo');
更新代码
app.use( session({ secret: 'story book', resave: false, saveUninitialized: false, store: MongoStore.create({ mongoUrl: YourDatabaseURL }) }) );
评论
index.js