4

我在 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)

当我转到 url '/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'));
});

过程文件:

web: node app.js

如果我继续刷新,它会使应用程序崩溃。

4

3 回答 3

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"
  }
}
于 2012-08-03T04:31:36.227 回答
1

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

vmc push yourappname --runtime node08

我希望我能帮助你

于 2012-08-14T10:01:03.617 回答
1

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

heroku 配置:添加 NODE_ENV=production

这与 Silas 提到的指定 Node 和 NPM 的版本有关。

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

于 2013-01-06T07:35:31.743 回答