Expressjs没有在heroku上加载样式表,给出500错误

时间:2012-08-03 04:19:45

标签: node.js express stylesheet pug stylus

我在heroku上运行Expressjs安装,但它没有加载样式表。

我点击ctrl + u然后点击样式表链接,并收到此错误:

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)

当我转到网址'/stylesheets/style.css'时,我收到此错误:

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

一切都在当地运作良好。

这是package.json

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

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

Procfile:

web: node app.js

如果我一直刷新,它会崩溃应用程序。

3 个答案:

答案 0 :(得分:13)

我能够通过在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"
  }
}

答案 1 :(得分:1)

我找到了答案! 你有一个错误的应用程序推送到云端的运行时 你可以这样做

vmc push yourappname --runtime node08

我希望我能帮到你

答案 2 :(得分:1)

我遇到了同样的问题,发现运行以下命令(通过Heroku CLI)对我有用:

heroku config:添加NODE_ENV =生产

这与Silas提到的指定Node和NPM的版本一起使用。

(通过http://quickleft.com/blog/getting-started-with-express-in-node