Heroku, Express & Node Bug – 500 TypeError: Object # has no method ‘randomBytes’

6 Jan

I decided I needed to write a post about this error, because the solution took me forever to find, so hopefully some poor soul stumbles across this and doesn’t waste as much time on this as I had to.

Basically if you get a nasty error output from your app when it is live on heroku, the first step is to type “heroku logs” into your terminal. This command pulls your app’s HTTP logs and spits it on screen.

Here was what I recieved:

Error: Can’t use mutable header APIs after sent.

[web.1]: at app/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js:64:17
[web.1]: at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
[web.1]: at ServerResponse.<anonymous> (/app/node_modules/express/node_modules/connect/lib/middleware/logger.js:149:20)
[web.1]: at generate (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:288:13)
[web.1]: at [object Object].<anonymous> (fs.js:107:5)
[web.1]: at wrapper (fs.js:245:17)
[web.1]: TypeError: Object #<Object> has no method ‘randomBytes’
[web.1]: at ServerResponse.getHeader (http.js:543:11)
[web.1]: at [object Object].emit (events.js:61:17)
[web.1]: at Object.session [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:297:7)
[web.1]: at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15)
[web.1]: throw new Error(“Can’t use mutable header APIs after sent.”);
heroku[web.1]: Process exited with status 1
[web.1]: at Object.methodOverride [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:37:5)
app[web.1]: ^
app[web.1]: at ServerResponse.<anonymous> (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:277:36)
[web.1]: at Object.uid (/app/node_modules/express/node_modules/connect/lib/utils.js:117:17)
[web.1]: at Object.cookieParser [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5)

While this isn’t the most useful error output, at least to me, some extensive google searching told me that this happens as a result of incompatible Framework versions. Essentially my version of Express was attempting to call methods that don’t exist on the default version of Node.js that Heroku provides.

The Fix! You can read here. Basically you need to specify which version of Node.js you want Heroku to use with your app. I have no porting issues at this point, so I’ve opted for Node.js 0.8.x.

Hope that helps someone, happy devving!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 153 other followers

%d bloggers like this: