Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expressjs not loading stylesheets on heroku, giving 500 error

I'm running an Expressjs installation on heroku, and it's not loading the stylesheets.

I hit ctrl+u and then click on the stylesheet link, and get this error:

TypeError: Object #<SendStream> has no method 'on'
    at Object.static [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/static.js:75:8)
    at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)

When I go to the url '/stylesheets/style.css' I get this error:

Express
500 TypeError: Object #<SendStream> has no method 'on'

    at Object.static [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/static.js:75:8)
    at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at /app/node_modules/stylus/lib/middleware.js:174:46
    at /app/node_modules/stylus/lib/middleware.js:208:20

Everything works fine locally.

here is the package.json

  {
    "name": "app-name",
      "version": "0.0.1",
      "private": true,
      "scripts": {
      "start": "node app"
     },
     "dependencies": {
       "express": "3.0.0rc1",
       "jade": "*",
       "stylus": "*"
     }
   }

The app.js:

/**
 * Module dependencies.
 */
 var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(require('stylus').middleware(__dirname + '/public'));
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);
app.get('/about', routes.about);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

The Procfile:

web: node app.js

If I keep refreshing, it crashes the app.

like image 850
silasjmatson Avatar asked Dec 07 '22 13:12

silasjmatson


2 Answers

I was able to solve this by specifying the engine dependencies in the package.json

{
  "name": "app-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.0.0rc1",
    "jade": "*",
    "stylus": "*"
  },
  "engines": {
    "node": "0.8.4",
    "npm": "1.1.41"
  }
}
like image 194
silasjmatson Avatar answered Dec 09 '22 02:12

silasjmatson


I found the answer! you got a wrong runtime of the application push to the cloud you can do this

vmc push yourappname --runtime node08

i hope i can help you

like image 21
ice4c Avatar answered Dec 09 '22 01:12

ice4c