2013-12-14 95 views
1

我已經研究過這個問題,但是我還沒辦法處理。在heroku上找不到模塊'socket.io'

我的節點和socket.io簡單的應用程序在我的本地計算機上運行良好,但不在heroku上。

Socket.io包括在的package.json

我跑 '的Heroku運行bash的',並列出安裝在Heroku和socket.io是不存在的node_modules。但在我的本地計算機上,socket.io似乎已安裝。

我'heroku摧毀myapp',然後再次創建它。 我運行以下腳本幾次

git add . 
git commit -am "comment" 
git push heroku master 

如何使Heroku的安裝socket.io模塊?我不確定這是否是真正的問題。

任何線索?

非常感謝。

Heroku的日誌:

app[web.1]: connect.limit() will be removed in connect 3.0 
app[web.1]: connect.multipart() will be removed in connect 3.0 
app[web.1]: visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives 
app[web.1]: Express app started on port 21105 
app[web.1]: 
app[web.1]: module.js:340 
app[web.1]:  throw err; 
app[web.1]:   ^
app[web.1]:  at Function.Module._load (module.js:280:25) 
app[web.1]:  at require (module.js:380:17) 
app[web.1]: Error: Cannot find module 'socket.io' 
app[web.1]:  at Object.<anonymous> (/app/server.js:46:37) 
app[web.1]:  at Module._compile (module.js:456:26) 
app[web.1]:  at Object.Module._extensions..js (module.js:474:10) 
app[web.1]:  at Function.Module._resolveFilename (module.js:338:15) 
app[web.1]:  at Module.require (module.js:364:17) 
app[web.1]:  at module.exports (/app/config/games/anagrammix.js:11:11) 
app[web.1]:  at Function.Module._load (module.js:312:12) 
app[web.1]:  at Module.load (module.js:356:32) 
app[web.1]: error: Forever detected script exited with code: 8 
heroku[run.1160]: State changed from up to complete 
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 
heroku[web.1]: Stopping process with SIGKILL 
heroku[web.1]: Process exited with status 137 
heroku[web.1]: State changed from starting to crashed 

的package.json:

{ 
    "name": "xxx", 
    "description": "gaming", 
    "version": "1.0.0", 
    "private": false, 
    "author": "xxx", 
    "engines": { 
    "node": "0.10.x", 
    "npm": "1.2.x" 
    }, 
    "scripts": { 
    "start": "NODE_ENV=development ./node_modules/.bin/nodemon server.js", 
    "test": "NODE_ENV=test ./node_modules/.bin/mocha --reporter spec test/test-*.js" 
    }, 
    "dependencies": { 
    "express": "latest", 
    "jade": "latest", 
    "mongoose": "latest", 
    "connect-mongo": "latest", 
    "connect-flash": "latest", 
    "passport": "latest", 
    "passport-local": "latest", 
    "passport-facebook": "latest", 
    "passport-twitter": "latest", 
    "passport-github": "latest", 
    "passport-google-oauth": "latest", 
    "underscore": "latest", 
    "gzippo": "latest", 
    "async": "latest", 
    "view-helpers": "latest", 
    "forever": "latest", 
    "socket.io":"latest" 
    }, 
    "devDependencies": { 
    "supertest": "latest", 
    "should": "latest", 
    "mocha": "latest", 
    "nodemon": "latest" 
    } 
} 

server.js:

/** 
* Module dependencies. 
*/ 

var express = require('express') 
    , fs = require('fs') 
    , passport = require('passport'); 

/** 
* Main application entry file. 
* Please note that the order of loading is important. 
*/ 

// Load configurations 
// if test env, load example file 
var env = process.env.NODE_ENV || 'test' 
    , config = require('./config/config')[env] 
    , auth = require('./config/middlewares/authorization') 
    , mongoose = require('mongoose'); 

// Bootstrap db connection 
mongoose.connect(config.db); 

// Bootstrap models 
var models_path = __dirname + '/app/models' 
fs.readdirSync(models_path).forEach(function (file) { 
    require(models_path+'/'+file); 
}); 

// bootstrap passport config 
require('./config/passport')(passport, config); 

var app = express(); 
// express settings 
require('./config/express')(app, config, passport); 

// Bootstrap routes 
require('./config/routes')(app, passport, auth); 

// Start the app by listening on <port> 
var port = process.env.PORT || 3000; 
var server = app.listen(port); 
console.log('Express app started on port '+port); 

//game settings 
require('./config/games/anagrammix')(server); 

// expose app 
exports = module.exports = app; 

anagrammix.js:

/** 
* Module dependencies. 
*/ 

var agx = require('../../app/games/anagrammix/agxgame'); 


module.exports = function (server) { 

    // Create a Socket.IO server and attach it to the http server 
    var io = require('socket.io').listen(server); 

    // Reduce the logging output of Socket.IO 
    io.set('log level',1); 

    // Heroku won't actually allow us to use WebSockets 
    // so we have to setup polling instead. 
    // https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku 
    io.configure(function() { 
     io.set("transports", ["xhr-polling"]); 
     io.set("polling duration", 10); 
    }); 

    // Listen for Socket.IO Connections. Once connected, start the game logic. 
    io.sockets.on('connection', function (socket) { 
     //console.log('client connected'); 
     agx.initGame(io, socket); 
    }); 

} 

回答

1

您是否試圖用*替換latest

https://npmjs.org/doc/json.html(詳見 「依賴性」)

+0

現在我試過但沒有工作。還是一樣的錯誤。謝謝btw。 – gox9

+0

@gogu這很奇怪。當你做'git push'時,你是否從npm中得到任何錯誤/警告?唯一讓我想到的是,也許Heroku使用'nodemon'來運行npm ...嘗試刪除腳本/啓動節並在Procfile中使用它 – Salem

0

我發現了一個solution爲我的作品。

它說從.gitignore文件中刪除node_modules文件夾,以便您可以將它們推送到heroku。

但它不完全是我正在尋找。以某種方式,heroku應該自動執行此安裝,因爲socket.io位於package.json中。我不明白爲什麼它只跳過socket.io。

相關問題