gpt4 book ai didi

typescript - 无法在本地测试云功能,模拟器无法启动并出现 TypeError : _onRequestWithOpts is not a function

转载 作者:搜寻专家 更新时间:2023-10-30 20:33:54 24 4
gpt4 key购买 nike

当我尝试从项目中的函数目录启动用于本地测试的 shell 时,模拟器启动但无法加载我的函数。

当我运行“npm run build”时,我没有收到任何错误。发生了什么事?

我尝试删除函数目录并使用 firebase-tools cli 重新创建它,但我仍然遇到相同的错误。我还导出了管理员凭据。

我使用的是在从 firebase-tools cli 生成的 index.ts 文件中创建的默认方法。

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request,
response) => {
response.send("Hello from Firebase!");
});

我希望模拟器启动函数的实例进行测试,但相反,我看到了这个错误:

✔  functions: Emulator started at http://localhost:5001
⚠ TypeError: _onRequestWithOpts is not a function
at Object.httpsProvider._onRequestWithOpts (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:278:24)
at Object.httpsProvider.onRequest (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:283:34)
at Object.<anonymous> (/Volumes/G-DRIVE mobile USB-C/CLEAN UP/Documents/code_bank/typescript/theincrowdapp/functions/lib/index.js:9:38)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
⚠ We were unable to load your functions code. (see above)
- It appears your code is written in Typescript, which must be compiled before emulation.
- You may be able to run "npm run build" in your functions directory to resolve this.

最佳答案

如果您遇到此错误,请在 functions 目录中运行 npm install firebase-functions@3.0.2

此问题将很快得到修复,您可以按照此处进行操作: https://github.com/firebase/firebase-tools/issues/1480

关于typescript - 无法在本地测试云功能,模拟器无法启动并出现 TypeError : _onRequestWithOpts is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56947574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com