Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 找不到模块';socket.io';论赫罗库_Node.js_Heroku_Socket.io - Fatal编程技术网

Node.js 找不到模块';socket.io';论赫罗库

Node.js 找不到模块';socket.io';论赫罗库,node.js,heroku,socket.io,Node.js,Heroku,Socket.io,我已经研究过这个问题,但还不能解决 我的带有node和socket.io的简单应用程序在本地计算机上运行良好,但在heroku上不起作用 Socket.io包含在package.json中 我运行“heroku run bash”并列出安装在heroku上的node_模块,socket.io不在那里。但在我的本地计算机上,似乎安装了socket.io 我“heroku销毁我的应用程序”,然后再次创建它。 我多次运行以下脚本 git add . git commit -am "comment" g

我已经研究过这个问题,但还不能解决

我的带有node和socket.io的简单应用程序在本地计算机上运行良好,但在heroku上不起作用

Socket.io包含在package.json中

我运行“heroku run bash”并列出安装在heroku上的node_模块,socket.io不在那里。但在我的本地计算机上,似乎安装了socket.io

我“heroku销毁我的应用程序”,然后再次创建它。 我多次运行以下脚本

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
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;

您是否尝试将依赖项中的
最新的
替换为
*


(请参阅“依赖项”)

您是否尝试用依赖项中的
*
替换
最新的

(参见“依赖项”)

我找到了一个适合我的

它说从.gitignore文件中删除node_modules文件夹,以便将它们推送到heroku

但这并不是我想要的。在某种程度上,heroku应该自动执行此安装,因为socket.io位于package.json中。我不明白为什么它只跳过socket.io。

我找到了一个适合我的

它说从.gitignore文件中删除node_modules文件夹,以便将它们推送到heroku


但这并不是我想要的。在某种程度上,heroku应该自动执行此安装,因为socket.io位于package.json中。我不明白为什么它只跳过socket.io。

现在我尝试了,但没有成功。还是一样的错误。谢谢你,顺便说一句。@gogu,这很奇怪。当您执行
git push
时,您没有收到来自npm的任何错误/警告吗?我唯一想到的是,也许Heroku正在使用
nodemon
运行npm。。。尝试删除scripts/start节并在procfile中使用它现在我尝试了,但没有成功。还是一样的错误。谢谢你,顺便说一句。@gogu,这很奇怪。当您执行
git push
时,您没有收到来自npm的任何错误/警告吗?我唯一想到的是,也许Heroku正在使用
nodemon
运行npm。。。尝试删除scripts/start节并在Procfile中使用它
/**
 * 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;
/**
 * 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);
    });

}