Firebase 模拟器没有 facilitating/running 新功能
Firebase emulator not facilitating/running new functions
我有三个云函数,其中两个已部署到我的 firebase 项目中,其中一个是我刚刚添加的。我希望在部署之前在本地测试新的,但是当我尝试使用它时我无法使用,只有两个已经部署的功能可用。
Firebase 模拟器 运行 在端口 5001
上运行正常。我按照 these instructions 添加了 firebase.functions().useEmulator("localhost", 5001);
到我想在本地测试的函数:
已经部署的函数示例:
// index.js
exports.addMessage = functions.region("europe-west1").https.onRequest(...
尚未部署的功能:
// index.js
exports.testFunction = functions.useEmulator("localhost", 5001).https.onRequest(...
然后我去了https://localhost:5001/{projectId}/us-central1/testFunction
,但是浏览器显示一条消息说只有addMessage
,我的其他部署的功能可以使用。我也尝试了 http
,正如另一个线程中推荐的那样。
这里有我遗漏的步骤吗?某种“本地”部署?我知道 firebase 版本有一些变化可能会把事情搞砸,但是当你 运行 firebase init
:
时,我使用默认的 imports/dependencies firebase 安装
// package.json
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
//index.js
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
编辑,新答案:
原来你需要将函数部署到firebase一次,模拟器才能识别函数。
运行 firebase deploy --only functions
然后模拟您的数据库,您应该会看到您的功能。
上一个回答:
运行 firebase setup:emulators:firestore
之后我新添加的功能似乎在模拟器中工作。
更新:
1: 在 firebase 中部署您的函数以获得识别。
你可以参考 Documentation 使用 firebase deploy --only functions
2:通过以下命令确保模拟器已安装:firebase setup:emulators:firestore
。为此,您可以参考 Documentation 如前所述:
The emulators:start command will start emulators for Cloud Functions,
Cloud Firestore, Realtime Database, and Firebase Hosting based on the
products you have initialized in your local project using firebase
init. If you want to start a particular emulator, use the --only flag.
如需进一步参考,您可以关注 Whosebug 线程 and ,其中 OP 提出了类似的问题,这可能会有所帮助。
我有三个云函数,其中两个已部署到我的 firebase 项目中,其中一个是我刚刚添加的。我希望在部署之前在本地测试新的,但是当我尝试使用它时我无法使用,只有两个已经部署的功能可用。
Firebase 模拟器 运行 在端口 5001
上运行正常。我按照 these instructions 添加了 firebase.functions().useEmulator("localhost", 5001);
到我想在本地测试的函数:
已经部署的函数示例:
// index.js
exports.addMessage = functions.region("europe-west1").https.onRequest(...
尚未部署的功能:
// index.js
exports.testFunction = functions.useEmulator("localhost", 5001).https.onRequest(...
然后我去了https://localhost:5001/{projectId}/us-central1/testFunction
,但是浏览器显示一条消息说只有addMessage
,我的其他部署的功能可以使用。我也尝试了 http
,正如另一个线程中推荐的那样。
这里有我遗漏的步骤吗?某种“本地”部署?我知道 firebase 版本有一些变化可能会把事情搞砸,但是当你 运行 firebase init
:
// package.json
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
//index.js
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
编辑,新答案:
原来你需要将函数部署到firebase一次,模拟器才能识别函数。
运行 firebase deploy --only functions
然后模拟您的数据库,您应该会看到您的功能。
上一个回答:
运行 firebase setup:emulators:firestore
之后我新添加的功能似乎在模拟器中工作。
更新:
1: 在 firebase 中部署您的函数以获得识别。
你可以参考 Documentation 使用 firebase deploy --only functions
2:通过以下命令确保模拟器已安装:firebase setup:emulators:firestore
。为此,您可以参考 Documentation 如前所述:
The emulators:start command will start emulators for Cloud Functions, Cloud Firestore, Realtime Database, and Firebase Hosting based on the products you have initialized in your local project using firebase init. If you want to start a particular emulator, use the --only flag.
如需进一步参考,您可以关注 Whosebug 线程