gpt4 book ai didi

node.js - Heroku 说 : Cannot find module 'socket.io'

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:52 25 4
gpt4 key购买 nike

我正在使用 deps/modules 部署一个 node.js 应用程序,例如 heroku 上的 stylus、express、socket.io。

server.js的开头

/**
* Bootstrap app.
*/

// I've tried with and without that line... not sure what it does
require.paths.unshift(__dirname + '/../../lib/');



/**
* Module dependencies.
*/

// I've tried with "socket.io", "./socket.io" and "Socket.IO"
var express = require('express')
, stylus = require('stylus')
, nib = require('nib')
, sio = require('socket.io');

文件 package.json

{ "name": "test.io" , "description": "blabla" , "version": "0.0.1" , "dependencies": { "express": "2.3.11" , "jade": "0.12.1" , "stylus": "0.13.3" , "nib": "0.0.8" } }

所以唯一的 heroku web worker 崩溃了。这是日志:

2011-10-24T09:15:27+00:00 heroku[slugc]: Slug compilation finished
2011-10-24T09:15:35+00:00 heroku[web.1]: Unidling
2011-10-24T09:15:35+00:00 heroku[web.1]: State changed from down to created
2011-10-24T09:15:35+00:00 heroku[web.1]: State changed from created to starting
2011-10-24T09:15:39+00:00 heroku[web.1]: State changed from starting to crashed
2011-10-24T09:15:39+00:00 heroku[web.1]: State changed from crashed to created
2011-10-24T09:15:39+00:00 heroku[web.1]: State changed from created to starting
2011-10-24T09:15:41+00:00 heroku[web.1]: Starting process with command `node app.js`
2011-10-24T09:15:41+00:00 app[web.1]:
2011-10-24T09:15:41+00:00 app[web.1]: node.js:134
2011-10-24T09:15:41+00:00 app[web.1]: throw e; // process.nextTick error, or 'error' event on first tick
2011-10-24T09:15:41+00:00 app[web.1]: ^
2011-10-24T09:15:41+00:00 app[web.1]: Error: Cannot find module 'socket.io'
2011-10-24T09:15:41+00:00 app[web.1]: at Function._resolveFilename (module.js:320:11)
2011-10-24T09:15:41+00:00 app[web.1]: at Function._load (module.js:266:25)
2011-10-24T09:15:41+00:00 app[web.1]: at require (module.js:348:19)
2011-10-24T09:15:41+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:18:11)
2011-10-24T09:15:41+00:00 app[web.1]: at Module._compile (module.js:404:26)
2011-10-24T09:15:41+00:00 app[web.1]: at Object..js (module.js:410:10)
2011-10-24T09:15:41+00:00 app[web.1]: at Module.load (module.js:336:31)
2011-10-24T09:15:41+00:00 app[web.1]: at Function._load (module.js:297:12)
2011-10-24T09:15:41+00:00 app[web.1]: at Array.<anonymous> (module.js:423:10)
2011-10-24T09:15:41+00:00 app[web.1]: at EventEmitter._tickCallback (node.js:126:26)
2011-10-24T09:15:41+00:00 heroku[web.1]: Process exited
2011-10-24T09:15:44+00:00 heroku[web.1]: State changed from starting to crashed

那么,有什么想法吗?有人遇到过吗?

最佳答案

我认为您应该在 package.json 的依赖项中添加 socket.io。

{ "name": "test.io" , "description": "blabla" , "version": "0.0.1" , "dependencies": { "express": "2.3.11" , "jade": "0.12.1" , "stylus": "0.13.3" , "nib": "0.0.8" , "socket.io" : "0.8.5" } }

或者只是这样做:

npm install socket.io --save

这将安装最新版本的 socket.io 并将其添加到依赖项中。

关于node.js - Heroku 说 : Cannot find module 'socket.io' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7873517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com