问题描述
我正在尝试在本地环境中运行firebase cloud functions
仿真器,但遇到EADDRINUSE
问题。
- 我可以成功运行firebase模拟器:
✔ functions[main]: http function initialized (http://localhost:5001/firebaseapp/main).
┌───────────────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘
┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
└───────────┴────────────────┴─────────────────────────────────┘
Other reserved ports: 4400,4500
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
> Server Started
> Connected to MongoDB
- 但是,在那之后事情并没有按预期进行,当我使用模拟器提供的链接时:
http://localhost:5001/firebaseapp/main
提出我的测试请求:
http://localhost:5001/firebaseapp/main/test
我收到以下错误:
> events.js:288
> throw er; // Unhandled 'error' event
> ^
>
> Error: listen EADDRINUSE: address already in use :::5000
> at Server.setupListenHandle [as _listen2] (net.js:1309:16)
> at listenInCluster (net.js:1357:12)
> at Server.listen (net.js:1445:7)
> at Function.listen (/Users/Desktop/fb_tour/functions/node_modules/express/lib/application.js:618:24)
> at Object.<anonymous> (/Users/Desktop/fb_tour/functions/index.js:61:5)
> at Module._compile (internal/modules/cjs/loader.js:1158:30)
> at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
> at Module.load (internal/modules/cjs/loader.js:1002:32)
> at Function.Module._load (internal/modules/cjs/loader.js:901:14)
> at Module.require (internal/modules/cjs/loader.js:1044:19)
> at require (internal/modules/cjs/helpers.js:77:18)
> at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:681:33
> at Generator.next (<anonymous>)
> at fulfilled (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:5:58)
> at processticksAndRejections (internal/process/task_queues.js:97:5)
> Emitted 'error' event on Server instance at:
> at emitErrorNT (net.js:1336:8)
> at processticksAndRejections (internal/process/task_queues.js:84:21) {
> code: 'EADDRINUSE',> errno: 'EADDRINUSE',> syscall: 'listen',> address: '::',> port: 5000
> }
我试图杀死端口5000,但显然没有活动的PID进程,因此我无法获取PID。我还重新启动了计算机,以强制关闭每个进程,但此错误仍然存在。
有什么建议吗?
编辑:即使更改了nodejs应用程序中的侦听端口,我也遇到了同样的问题。例如设置端口3000时,我收到相同的错误消息,提示该端口3000已在使用中。
编辑2:我想我已经确定了问题的原因。运行功能模拟器时出现此警告消息
It seems that you are running multiple instances of the emulator suite for project firebaseapp. This may result in unexpected behavior.
我认为我的应用程序有两个实例同时运行,从而导致此错误。但是我不知道如何解决这个问题。
解决方法
如果您的功能代码中有app.listen()
,请删除它,然后一切正常。
对于您提供的最新更新,该错误消息是在github上报告的,我认为您可以按照那里的建议进行操作,以避免出现此问题。
似乎您只需要使用CTRL-C命令即可使用模拟器。根据{{3}},该问题已解决。