Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module './lib/socket.io'

I had my server working with an earlier version of node.js, npm, and socket.io but after updating I started getting issues with socket.io:

$ node server.js

node.js:237
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module './lib/socket.io'
    at Function._resolveFilename (module.js:333:15)
    at Function._load (module.js:280:25)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/socket.io/index.js:8:18)
    at Module._compile (module.js:444:26)
    at Object..js (module.js:462:10)
    at Module.load (module.js:351:32)
    at Function._load (module.js:309:12)
    at Module.require (module.js:357:17)

Before upgrading I had a symlink for socket.io under node_modules pointing to the "centrally installed" directory with the same name. Recently I tried installing socket.io local to my project by issuing the command:

npm install socket.io

which placed socket.io under node_modules in my project. I found it strange at first that the error message was saying "./lib/socket.io" but when I looked into it I found that project/node_modules/socket.io/index.js is requiring socket.io like so:

module.exports = require('./lib/socket.io');

But there is nothing there except transport:

...project/node_modules/socket.io/lib
$ ll
total 24
drwxrwxr-x 3 ghbarratt dev  4096 Mar 26 14:38 .
drwxrwxr-x 5 ghbarratt dev  4096 Mar 26 15:03 ..
-rw-rw-r-- 1 ghbarratt dev 10777 Mar  6 16:37 transport.js
drwxrwxr-x 3 ghbarratt dev  4096 Mar 26 14:38 transports

Should there be another socket.io directory or a socket.io.js file under lib? Why would index.js be requiring an internal file that seems to be missing?

Versions:

node -v
v0.7.7-pre

npm -v
1.1.12

[email protected]

Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:        10.10
Codename:       maverick
like image 918
ghbarratt Avatar asked Mar 26 '12 19:03

ghbarratt


1 Answers

I hate to answer my own question, but I did get things resolved and there were no other answers so I am going to add this in case it can help someone else.

With Felix Loether's comment (which I +1ed) I was fairly certain that I did not get all the files I should have during the npm install socket.io. I tried doing an apt-get update/upgrade, thinking that I might need an update for tar or something, but the results were still the same.

I was noticing a 304 response in the install output and wondered at that point if there was some sort of npm cache that I should try clearing. I discovered I could clear the npm cache with the command: npm cache clean. Cleaning the cache finally got me past the no-errors-until-runtime issue.

I then started to get an error message: make: node-waf: Command not found which lead me to reinstall node.

And after all that, it worked!

like image 95
ghbarratt Avatar answered Nov 08 '22 13:11

ghbarratt