【问题标题】:Impossible to execute my firebase functions locally无法在本地执行我的 firebase 功能
【发布时间】:2020-12-18 15:02:05
【问题描述】:

我正在尝试在本地环境中运行 firebase cloud functions 模拟器,但遇到了 EADDRINUSE 问题。

  1. 我可以成功运行 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
  1. 但是,当我使用模拟器提供的链接时,事情并没有按预期进行:

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.

我认为我的应用程序有两个实例同时运行,导致此错误。但是我不知道如何解决这个问题。

【问题讨论】:

  • 如果您有包含特定复制说明的 Firebase CLI 错误报告,请在 GitHub 上提交错误报告。 github.com/firebase/firebase-tools
  • 尝试杀死 5001 上的进程
  • 我一直这样做,在开发过程中,如果代码中出现未处理的异常,他们可能会在中间抛出错误,我会在地址已在使用错误后杀死 5001
  • @vinoth10 正如我在编辑中所说,我刚刚找到了导致此问题的原因。我收到此警告消息It seems that you are running multiple instances of the emulator suite for project firebaseapp. This may result in unexpected behavior.,但我不知道为什么我的应用程序上的多个实例同时运行。
  • 我之前在编写云函数时遇到过这个问题。首先,您不需要传递所有这些详细信息来启动管理应用程序。我所做的只是将import * as admin from 'firebase-admin'; admin.initializeApp(); 作为 index.ts/index.js 中的前 2 行,然后 import * as admin from 'firebase-admin'; const db = admin.firestore();在各自的云功能中

标签: node.js firebase express google-cloud-functions firebase-cli


【解决方案1】:

对于您提供的最新更新,错误消息是在github 上报告的,我认为您可以按照那里的建议来避免该问题。

您似乎只需要在使用模拟器之前使用 CTRL-C 命令。根据这个link,问题已经解决了。

【讨论】:

    【解决方案2】:

    如果您的函数代码中有app.listen(),则将其删除,一切正常。

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 1970-01-01
      • 2020-02-05
      • 2019-10-06
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2017-08-03
      • 2020-02-26
      相关资源
      最近更新 更多