[Node.js] Installed socketio instead of socket.io and got 'Cannot find module 'socket.io'' error
I wanted to use socket.io and after installing with npm install socketio —save, when I tried require(‘socket.io’), I got Error: Cannot find module ‘socket.io’ and spent tens of minutes wondering “Why…?”
$ node index.js
module.js:327
throw err;
^
Error: Cannot find module 'socket.io'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/Users/username/works/sample/index.js:9:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
As it turned out, socketio was not the module I should use, and the correct one is socket.io. After fixing package.json as shown below and running npm install again, I was able to require(‘socket.io’) successfully.
diff --git a/package.json b/package.json
index 30cdfac..84192a7 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,6 @@
- "socketio": "^1.0.0"
+ "socket.io": "^1.5.1"
}
}
I’d prefer if they didn’t use the confusing package name socketio.
That’s all from the Gemba.