错误:找不到模块'socket.io'

时间:2021-10-08 12:19:47
[~]# node node.js

Error: Cannot find module 'socket.io'

[~]# node -v
v0.10.10

socket.io installed:

套接字。io安装:

npm install socket.io

npm WARN package.json policyfile@0.0.4 No repository field.
npm WARN package.json policyfile@0.0.4 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field

5 个解决方案

#1


49  

Looks like you have installed socket.io in a different location to your current path. Either install globally like below:

看起来您已经安装了套接字。io在当前路径的不同位置。可以在全球安装如下:

npm install -g socket.io

npm安装- g socket . io

Or reference the location you've installed to:

或参考你安装的位置:

var io = require('../lib/socket.io');

#2


8  

Thanks ajtrichards!

谢谢ajtrichards !

Just to add to the answer - in case you simple use

只是为了增加答案——如果你使用简单的话。

sudo npm install socket.io

The installation path will be

安装路径将是。

/home/.../.npm/socket.io

If you use sudo npm install -g socket.io

如果你使用sudo npm安装-g socket.io。

The installation path will be

安装路径将是。

/usr/local/lib/node_modules/socket.io

In first case, I tried adding the socket.io path in global path variable but it did not work.

在第一种情况下,我尝试添加套接字。io路径在全局路径变量中,但它不起作用。

#3


4  

I had the same issue with version 0.12.0 on Windows. I tried npm install -g socket.io but that didn't change anything. Also tried npm cache clean also no change, but after npm update npm -g, things got well.

我在Windows上的版本0.12.0也有同样的问题。我尝试了npm安装-g插座。但那并没有改变什么。也尝试了npm高速缓存也没有变化,但是在npm更新npm -g之后,事情变得很好。

#4


1  

This almost happens than you try to get socket.io in you html files like :

这几乎是发生在你试图获取套接字的时候。io在你的html文件,如:

index.html

index . html

where you have:

你有去的地方:

 < script type="text/javascript" src="/socket.io/socket.io.js"></script>

It will not find socket.io because you did not started module in you application file wich contain the server like

它不会找到套接字。io因为你没有启动模块在你的应用程序文件中包含了服务器。

server.js

server.js

You must include following lines after started your server in server.js :

在服务器启动服务器后,必须包括以下几行。js:

var io = require('socket.io').listen(server);

Hope, will save time.

希望,能节省时间。

#5


0  

I think that you have executed the command npm install socket.io in a different location and your files are in different directory.. So either run the command in the same directory which have your files or either mention the path where you have currently installed socket.io in your PATH variable.

我认为您已经执行了命令npm安装套接字。io在不同的位置,你的文件在不同的目录。因此,要么在具有文件的相同目录中运行该命令,要么在当前安装了套接字的地方提到该路径。在路径变量中输入io。

#1


49  

Looks like you have installed socket.io in a different location to your current path. Either install globally like below:

看起来您已经安装了套接字。io在当前路径的不同位置。可以在全球安装如下:

npm install -g socket.io

npm安装- g socket . io

Or reference the location you've installed to:

或参考你安装的位置:

var io = require('../lib/socket.io');

#2


8  

Thanks ajtrichards!

谢谢ajtrichards !

Just to add to the answer - in case you simple use

只是为了增加答案——如果你使用简单的话。

sudo npm install socket.io

The installation path will be

安装路径将是。

/home/.../.npm/socket.io

If you use sudo npm install -g socket.io

如果你使用sudo npm安装-g socket.io。

The installation path will be

安装路径将是。

/usr/local/lib/node_modules/socket.io

In first case, I tried adding the socket.io path in global path variable but it did not work.

在第一种情况下,我尝试添加套接字。io路径在全局路径变量中,但它不起作用。

#3


4  

I had the same issue with version 0.12.0 on Windows. I tried npm install -g socket.io but that didn't change anything. Also tried npm cache clean also no change, but after npm update npm -g, things got well.

我在Windows上的版本0.12.0也有同样的问题。我尝试了npm安装-g插座。但那并没有改变什么。也尝试了npm高速缓存也没有变化,但是在npm更新npm -g之后,事情变得很好。

#4


1  

This almost happens than you try to get socket.io in you html files like :

这几乎是发生在你试图获取套接字的时候。io在你的html文件,如:

index.html

index . html

where you have:

你有去的地方:

 < script type="text/javascript" src="/socket.io/socket.io.js"></script>

It will not find socket.io because you did not started module in you application file wich contain the server like

它不会找到套接字。io因为你没有启动模块在你的应用程序文件中包含了服务器。

server.js

server.js

You must include following lines after started your server in server.js :

在服务器启动服务器后,必须包括以下几行。js:

var io = require('socket.io').listen(server);

Hope, will save time.

希望,能节省时间。

#5


0  

I think that you have executed the command npm install socket.io in a different location and your files are in different directory.. So either run the command in the same directory which have your files or either mention the path where you have currently installed socket.io in your PATH variable.

我认为您已经执行了命令npm安装套接字。io在不同的位置,你的文件在不同的目录。因此,要么在具有文件的相同目录中运行该命令,要么在当前安装了套接字的地方提到该路径。在路径变量中输入io。