简体   繁体   中英

Type error while hosting node.js app on Heroku

I have my node.js app with dependencies

{
  "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"
  }

}

it is working fine on my localhost

When i am hosting my node app on heroku i am getting the following error.

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)

I tried to remove lines one by one and get to this where i removed

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

The app was giving the "Hello World" response. See my complete code below.

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");
});

Please help me out.

I was having the same issue. It was resolved by adding the "engines" block to package.json which directs Heroku to use a specific version of node and npm. Most likely you are using a much newer version of node than the Heroku default 0.4.7

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM