简体   繁体   English

Firebase 云 function 本地代码更改未反映在模拟器中

[英]Firebase cloud function local code changes are not reflected in emulators

I am trying to develop API for my apps using Firebase cloud functions.我正在尝试使用 Firebase 云函数为我的应用程序开发 API。
Following this site to use the firebase emulator suite for development and testing locally.跟随本站使用firebase模拟器套件在本地进行开发和测试。

Issue: The changes are not reflected in the locally emulated functions.问题:更改未反映在本地模拟函数中。

Steps:脚步:

  1. index.js:索引.js:

     exports.test = functions.https.onRequest(async (request, response) => { response.status(200).send("First"); });
  2. Successfully deployed the test method.成功部署test方法。

     firebase deploy --only functions:test
  3. In Postman made the following GET request.在 Postman 中发出了如下 GET 请求。

     https://us-central1-<project-name>.cloudfunctions.net/test

    Result: First结果:第一
    Status: 200 OK状态:200 正常

  4. Started the emulators:启动模拟器:

     firebase emulators:start --only functions
  5. In Postman made the following GET request.在 Postman 中发出了如下 GET 请求。

     http://localhost:5001/<project-name>/us-central1/indexTest

    Result: First结果:第一
    Status: 200 OK状态:200 正常
    Same as the actual deployed function.同实际部署的function。

  6. Changed the function code to:将 function 代码更改为:

     exports.test = functions.https.onRequest(async (request, response) => { response.status(200).send("Second"); });
  7. Getting the same result as before when hitting the emulated function in localhost.在本地主机中点击模拟的 function 时得到与以前相同的结果。 The changes are not reflected.不会反映更改。

Also, tried stopping the emulator and starting it again.另外,尝试停止模拟器并重新启动它。 No luck.没有运气。

I had raised an issue in the firebase-tools repo as suggested by DougStevenson.按照 DougStevenson 的建议,我在 firebase-tools 回购中提出了一个问题。 Got the issue resolved with Sam Stern's support.在 Sam Stern 的支持下解决了这个问题。

Posting the solution here for anyone else who gets stuck in the same issue.在此处为陷入同一问题的任何其他人发布解决方案。

Solution:解决方案:

  1. After every change to the ts files, run "npm run build" to compile the code again.每次更改 ts 文件后,运行“npm run build”再次编译代码。
  2. Change "build": "tsc" to "build": "tsc -w" in package.json if you want to auto-compile after every change.如果您想在每次更改后自动编译, package.json中的"build": "tsc"更改为"build": "tsc -w"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM