node.js 错误消息 events.js:183 throw er; // 未处理的“错误”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48765445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:41:10  来源:igfitidea点击:

node.js error message events.js:183 throw er; // Unhandled 'error' event

node.jsbotframeworksublimetext

提问by yu zhou

Playing around Microsoft's botframework, when I try to run the app.js file, which is the main file of the bot, the first time is fine, after I close the bot emulator, and all programs, and run the app.js again, this error message pops out

玩微软的botframework,当我尝试运行app.js文件时,这是bot的主文件,第一次没问题,在我关闭bot模拟器和所有程序后,再次运行app.js,此错误消息弹出

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3978
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at Server.setupListenHandle [as _listen2] (net.js:1351:14)
    at listenInCluster (net.js:1392:12)
    at Server.listen (net.js:1476:7)
    at Server.listen (C:\Users\yu\Documents\GitHub\BotBuilder-
Samples\Node\cards-AdaptiveCards\node_modules\restify\lib\server.js:404:32)
    at Object.<anonymous> (C:\Users\yu\Documents\GitHub\BotBuilder-
Samples\Node\cards-AdaptiveCards\app.js:10:8)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)

I found some solution to this, It looks like the port 3978 was taken when I run the js file for the second time, and I have to use cmd to find which task is using that port, and then kill the task.

我找到了一些解决方案,看起来我第二次运行js文件时3978端口被占用了,我必须使用cmd来查找哪个任务正在使用该端口,然后终止该任务。

C:\>netstat -aon|findstr 3978

so this one is taking the port, although I already closed all programs

所以这个正在使用端口,虽然我已经关闭了所有程序

TCP    0.0.0.0:3978           0.0.0.0:0              LISTENING       13140
TCP    [::]:3978              [::]:0                 LISTENING       13140

actually it is node.exe itself, it still running at background

实际上它是node.exe本身,它仍然在后台运行

C:\Users\yu>tasklist|findstr 13140
node.exe                     13140 Console                    1     42,064 K

and I need to kill it

我需要杀死它

C:\Users\yu>taskkill /f /t /im node.exe

Is there a way to not always repeat doing this when I want to run the file more than one time, it just starts to go wired today, and I mean for all different app.js files, include offical sample code. For the past one month, everything was fine, the IDE I am using is sublime text 3, node.js version is 8.9.4 lts

当我想多次运行文件时,有没有办法不总是重复执行此操作,它今天才开始连接,我的意思是对于所有不同的 app.js 文件,包括官方示例代码。过去一个月,一切都很好,我使用的IDE是sublime text 3,node.js版本是8.9.4 lts

回答by Natesh bhat

This is a very common issue and can be easily fixed by either of the below methods.

这是一个非常常见的问题,可以通过以下任一方法轻松解决。

  1. Try to close the process that is using your port.

    netstat -tulnp | grep <port_number>

  2. Installing the below pakcage fixed it for me forever.

    npm install [email protected] --save-dev --save-exact

  3. Run this command in your terminal :

    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

    For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf:

    fs.inotify.max_user_watches=524288

    Then execute:

    sysctl --system

    This will also persist across reboots.

    https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

  1. 尝试关闭正在使用您的端口的进程。

    netstat -tulnp | grep <port_number>

  2. 安装下面的包永远为我修复它。

    npm install [email protected] --save-dev --save-exact

  3. 在终端中运行此命令:

    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

    对于 Arch Linux,将此行添加到 /etc/sysctl.d/99-sysctl.conf:

    fs.inotify.max_user_watches=524288

    然后执行:

    sysctl --system

    这也将在重新启动后持续存在。

    https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

Either one of the solutions will work . If not then restart your system and check again.

任何一种解决方案都有效。如果没有,则重新启动系统并再次检查。

回答by Alireza

If you are on mac, to make sure nothing is running on the same port, do:

如果您使用的是mac,要确保同一端口上没有运行任何内容,请执行以下操作:

killall node

and restart your app.

并重新启动您的应用程序。

回答by Anush

The port you are listening to is already being listened by another process.

您正在侦听的端口已被另一个进程侦听。

When I faced to this error I killed the process using Windows PowerShell (because I used Windows)

当我遇到此错误时,我使用 Windows PowerShell 终止了该进程(因为我使用的是 Windows)

  1. open the windows powershell
  2. type psand then you can get list of processes
  3. find the process named node, and note the Id
  4. type Stop-process <Id>
  1. 打开 Windows PowerShell
  2. 输入ps然后你可以得到进程列表
  3. 找到名为node的进程,并记下Id
  4. 类型 Stop-process <Id>

I think that it is help for windows users.

我认为这对 Windows 用户有帮助。

回答by Raushan

I solved the issue using this command in my terminal on Linux.

我在 Linux 的终端中使用此命令解决了该问题。

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install

回答by Janith Udara

I also got the same problem and tried many ways but finally got this ,this work well

我也遇到了同样的问题并尝试了很多方法但最终得到了这个,这个工作很好

npm install [email protected] --save-dev --save-exact

npm install [email protected] --save-dev --save-exact

refer to this link for more clarifications https://github.com/ionic-team/ionic-cli/issues/2922

有关更多说明,请参阅此链接 https://github.com/ionic-team/ionic-cli/issues/2922

回答by Allan Jiang

Try specify a different port before you run the node.js application.

在运行 node.js 应用程序之前尝试指定不同的端口。

For example, if you have collision on port 3978, set a different port before you start the server.js:

例如,如果您在端口 3978 上发生冲突,请在启动 server.js 之前设置一个不同的端口:

export PORT=3979

export PORT=3979

回答by Jeyanth

I did also face the same problem. Installing of npm install [email protected] --save-dev --save-exactwas not fix this. Later I came to know that there is an another website hosted by IIS in the same port where I configured for Node JS express server. Stopping of IIS website can get rid out of this issue.

我也遇到了同样的问题。安装npm install [email protected] --save-dev --save-exact不是解决这个问题。后来我才知道,在我为 Node JS express 服务器配置的同一端口中,还有一个由 IIS 托管的网站。停止 IIS 网站可以解决这个问题。

回答by Manjunath N Karbhasgi

Even I was also getting the error while running node server. i.e events.js:183 throw er; // Unhandled 'error' event ^ In my case, I was getting that error because I had changed Mysql port number 3306 to 3307 while installing. I recovered from from that error by changing Mysql port number to 3306, and now its running.

即使我在运行节点服务器时也遇到错误。即 events.js:183 抛出 er; // 未处理的“错误”事件 ^ 就我而言,我收到该错误是因为我在安装时将 Mysql 端口号 3306 更改为 3307。我通过将 Mysql 端口号更改为 3306 从那个错误中恢复过来,现在它正在运行。

回答by Davijr

Find the process that is using the port and kill it.

找到正在使用该端口的进程并杀死它。

Assuming the server port is 8000.

假设服务器端口为 8000。

1) C:> netstat -aon | findstr 8000

1) C:> netstat -aon | findstr 8000

This command will return the Process ID (PID).

此命令将返回进程 ID (PID)。

2) C:> taskkill /F /PID 7848

2) C:> taskkill /F /PID 7848

This command will kill the Process by PID.

此命令将通过 PID 终止进程。

enter image description here

在此处输入图片说明

回答by MATTEO ZULUAGA LASSO

This happens when you open another project without having closed the one you were already using, remember to always use Ctrl+c when you finish using a project. Try rebooting your PC and it should work again. At least that's what worked for me.

当您打开另一个项目而没有关闭您已经使用的项目时会发生这种情况,请记住在完成使用项目后始终使用 Ctrl+c。尝试重新启动您的 PC,它应该会再次工作。至少这对我有用。