2012-08-03 51 views
4

我在heroku上運行Expressjs安裝,它不加載樣式表。Expressjs不加載在heroku樣式表,給500錯誤

我按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 

如果我保持清爽,它崩潰的應用程序。

回答

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

謝謝,這對我很有用! – 2012-08-27 21:20:48

+2

任何人都可以澄清爲什麼指定節點/ npm引擎版本解決了在快速靜態內容請求失敗的問題? 我投了票,因爲它爲我工作,但這有點莫名其妙?! – warriorpostman 2012-11-28 19:35:14

+0

我假設它默認使用錯誤的? ...比我多一點知識的人應該編輯我的答案,使其明確。 – silasjmatson 2012-11-28 19:44:22

1

我找到了答案! 你得到了應用推送的錯誤運行到雲 你可以這樣做

vmc push yourappname --runtime node08 

我希望我可以幫助你

+0

當你將應用程序推送到雲端時,你應該首先選擇[node04 node06 node08], 之一,並且一旦你選擇了node04和node06,那麼它可能會記住它, 因此你無法改變你的版本沒有你再次推送應用程序的節點 – ice4c 2012-08-14 10:02:35