why can't i find the module 'socket.io'?

2,822 views
Skip to first unread message

wahaha

unread,
Dec 30, 2011, 7:30:34 AM12/30/11
to nodejs
i have installed the module 'socket.io' currectly in 'C:\Documents and
Settings\xxx\node_modules'.
and i have checked that i can require the module 'socket.io' in cmd
successfully.
but when i require the module in a js file,it wrongs,the cmd console
said:
Error: Cannot find module 'socket.io'

i do not know why...

Isaac Schlueter

unread,
Dec 30, 2011, 12:59:36 PM12/30/11
to nod...@googlegroups.com
Please share the code you're using.

Works just fine for me. Observe:

c:\Users\Isaac Schlueter>mkdir socket.io-test

c:\Users\Isaac Schlueter>cd socket.io-test

c:\Users\Isaac Schlueter\socket.io-test>cat >test.js
require("socket.io")
console.log(require.resolve("socket.io"))
// press Control-D to finish

c:\Users\Isaac Schlueter\socket.io-test>mkdir node_modules

c:\Users\Isaac Schlueter\socket.io-test>npm install socket.io
npm http GET https://registry.npmjs.org/socket.io
npm http 200 https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/socket.io/-/socket.io-0.8.7.tgz
npm http 200 https://registry.npmjs.org/socket.io/-/socket.io-0.8.7.tgz
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/redis/0.6.7
npm http GET https://registry.npmjs.org/socket.io-client/0.8.7
npm http 200 https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/policyfile/-/policyfile-0.0.4.tgz
npm http 200 https://registry.npmjs.org/socket.io-client/0.8.7
npm http GET
https://registry.npmjs.org/socket.io-client/-/socket.io-client-0.8.
7.tgz
npm http 200 https://registry.npmjs.org/redis/0.6.7
npm http GET https://registry.npmjs.org/redis/-/redis-0.6.7.tgz
npm http 200
https://registry.npmjs.org/socket.io-client/-/socket.io-client-0.8.
7.tgz
npm http 200 https://registry.npmjs.org/policyfile/-/policyfile-0.0.4.tgz
npm http 200 https://registry.npmjs.org/redis/-/redis-0.6.7.tgz
npm http GET https://registry.npmjs.org/websocket-client/1.0.0
npm http GET https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http GET https://registry.npmjs.org/uglify-js/1.0.6
npm http 200 https://registry.npmjs.org/xmlhttprequest/1.2.2
npm http GET
https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.2.2.tg
z
npm http 200 https://registry.npmjs.org/uglify-js/1.0.6
npm http 200 https://registry.npmjs.org/websocket-client/1.0.0
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-1.0.6.tgz
npm http GET
https://registry.npmjs.org/websocket-client/-/websocket-client-1.0.
0.tgz
npm http 200
https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.2.2.tg
z
npm http 200
https://registry.npmjs.org/websocket-client/-/websocket-client-1.0.
0.tgz
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-1.0.6.tgz
sock...@0.8.7 ./node_modules/socket.io
├── polic...@0.0.4
├── re...@0.6.7
└── socket.i...@0.8.7

c:\Users\Isaac Schlueter\socket.io-test>node test.js
c:\Users\Isaac Schlueter\socket.io-test\node_modules\socket.io\index.js

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

Shinuza

unread,
Dec 30, 2011, 1:47:11 PM12/30/11
to nod...@googlegroups.com
Can you post some code? (Gist, pastie, etc...)

Glenn Block

unread,
Dec 30, 2011, 7:36:21 PM12/30/11
to nod...@googlegroups.com
How did you install it, via npm? Is your app sitting in "xxx"?

Glenn

wahaha

unread,
Dec 30, 2011, 9:12:39 PM12/30/11
to nodejs
the 1st step: C:\Documents and Settings\xxx,cmd,nmp install socket.io
the 2cnd step: cmd,node,require("socket.io").version,display: '0.8.7'
the 3rd step: create a file a.js,write:
console.log(require("socket.io").version);
the 4th step: cmd, node d:\a.js, display: Error: Cannot find module
'socket.io'

Shinuza

unread,
Dec 30, 2011, 10:10:55 PM12/30/11
to nod...@googlegroups.com
What's the output of 

console.log(module.paths);

?

wahaha

unread,
Dec 30, 2011, 11:59:50 PM12/30/11
to nodejs
[ 'C:\\Documents and Settings\\yuliang\\repl\\node_modules',
'C:\\Documents and Settings\\yuliang\\node_modules',
'C:\\Documents and Settings\\node_modules',
'C:\\node_modules' ]

Shinuza

unread,
Dec 31, 2011, 10:06:33 AM12/31/11
to nod...@googlegroups.com
Versions of node.js and npm, please?

Isaac Schlueter

unread,
Dec 31, 2011, 9:09:40 PM12/31/11
to nod...@googlegroups.com
Notice the problem? Look at the paths you mentioned:

>>>
the 1st step: C:\Documents and Settings\xxx,cmd,nmp install socket.io
the 2cnd step: cmd,node,require("socket.io").version,display: '0.8.7'
the 3rd step: create a file a.js,write:
console.log(require("socket.io").version);
the 4th step: cmd, node d:\a.js, display: Error: Cannot find module
'socket.io'
>>>

That file has to live somewhere under C:\Documents and settings\xxx.
npm installs packages locally to the current working directory. Since
you were in C:\Documents and Settings\xxx when you installed it, it
installed in C:\Documents and Settings\xxx\node_modules. So, your
file in d:\a.js can't see it! If you move that file to C:\Documents
and Settings\xxx\a.js, then it will work. Or, you can run `d:\` and
then `npm install socket.io` to install it there, as well.

Whenever you install something with npm, it outputs the location where
it got installed to. You can only access that package if you're under
that folder somewhere.

On Sat, Dec 31, 2011 at 07:06, Shinuza <samor...@gmail.com> wrote:
> Versions of node.js and npm, please?
>

Reply all
Reply to author
Forward
0 new messages