找不到模块' engine.io'

时间:2015-07-09 06:31:05

标签: node.js

我正在运行

var io = require('socket.io')(http);

这给了我这个错误:

module.js:340
    throw err;
          ^
Error: Cannot find module 'engine.io'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/harshil/chatapp/node_modules/socket.io/lib/index.js:9:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

我试过npm install -g engine.io,socket.io npm update -g npm 但同样,我总是得到这个错误

npm WARN unmet dependency /usr/local/lib/node_modules/socket-chat-example/node_modules/socket.io/node_modules/socket.io-adapter requires debug@'1.0.2' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/socket-chat-example/node_modules/socket.io/node_modules/debug,
npm WARN unmet dependency which is version 0.7.4

npm list给出了这个输出(仅显示错误部分)

└─┬ socket.io@1.2.0
  ├── UNMET DEPENDENCY debug@0.7.4
  ├── UNMET DEPENDENCY engine.io@1.4.2
  ├── UNMET DEPENDENCY has-binary-data@0.1.3
  ├── UNMET DEPENDENCY socket.io-adapter@0.3.1
  ├── UNMET DEPENDENCY socket.io-client@1.2.0
  └── UNMET DEPENDENCY socket.io-parser@2.2.2

npm ERR! missing: engine.io@1.4.2, required by socket.io@1.2.0
npm ERR! missing: socket.io-parser@2.2.2, required by socket.io@1.2.0
npm ERR! missing: socket.io-client@1.2.0, required by socket.io@1.2.0
npm ERR! missing: socket.io-adapter@0.3.1, required by socket.io@1.2.0
npm ERR! missing: has-binary-data@0.1.3, required by socket.io@1.2.0
npm ERR! missing: debug@0.7.4, required by socket.io@1.2.0

我该怎么办?

1 个答案:

答案 0 :(得分:4)

安装socket.io时应该已经安装了socket.io的依赖项,但它看起来没有发生,或者安装后可能会删除它们。无论如何,请将其卸载并重新安装:

npm uninstall socket.io && npm install socket.io

作为一般规则,除非您要安装命令行工具,否则不要将-gnpm install一起使用。只需在项目中安装依赖项即可。