gpt4 book ai didi

node.js - 在 Heroku 上托管 Node.js 应用程序时键入错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:51:23 25 4
gpt4 key购买 nike

我的 node.js 应用程序具有依赖项

{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": ">=2.2.0",
"jade": "*",
"stylus": "*",
"mongodb": ">= 0.9.6-7"
}

}

它在我的本地主机上运行良好

当我在 heroku 上托管我的 Node 应用程序时,我收到以下错误。

TypeError: Object # has no method 'randomBytes' at Object.uid (/app/node_modules/express/node_modules/connect/lib/utils.js:121:17) at MemoryStore.generate (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:204:27) at generate (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:288:13) at Object.session [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:297:7) at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.cookieParser [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5) at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.expressInit [as handle] (/app/node_modules/express/lib/middleware.js:31:5) at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.query [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)

我尝试逐行删除行并到达我删除的位置

app.use(express.session({ secret:'yodawgyo' }));

应用程序正在给出“Hello World”响应。请参阅下面我的完整代码。

var express = require('express');
var crypto = require('crypto');//for gravatar

var passport = require('passport')
, OpenIDStrategy = require('passport-openid').Strategy
, GoogleStrategy = require('passport-google').Strategy
, AOLStrategy = require('passport-aol').Strategy
, YahooStrategy = require('passport-yahoo').Strategy;;



passport.serializeUser(function(user, done) {
done(null, user);
});

passport.deserializeUser(function(obj, done) {
done(null, obj);
});

var app = module.exports = express();

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.cookieParser());


//NO ISSUES WITH HEROKU IF I COMMENTED BELOW LINE
app.use(express.session({ secret:'yodawgyo' }));


app.use(app.router);

});

app.get('/', function(req, res) {
res.send("Hello World");
});

app.listen(process.env.PORT || 5000, function() {
console.log("listening on 5000");
});

请帮帮我。

最佳答案

我也遇到了同样的问题。通过将“engines” block 添加到 package.json 来解决这个问题,该 block 指示 Heroku 使用特定版本的 Node 和 npm。您很可能使用比 Heroku 默认 0.4.7 更新得多的 Node 版本

参见https://devcenter.heroku.com/articles/nodejs-support#versions

关于node.js - 在 Heroku 上托管 Node.js 应用程序时键入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13842249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com