无法在本地测试云功能,模拟器无法以TypeError开头:_onRequestWithOpts不是函数 [英] Can't test cloud functions locally, emulator fails to start with TypeError: _onRequestWithOpts is not a function

查看:70
本文介绍了无法在本地测试云功能,模拟器无法以TypeError开头:_onRequestWithOpts不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从项目中的functions目录启动外壳程序进行本地测试时,模拟器会启动,但是我的函数无法加载.

When I try to start the shell for local testing from the functions directory in my project, the emulator starts but my functions are not able to be loaded.

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

When I run "npm run build" I receive no errors. What is happening?

我尝试删除功能目录并使用firebase-tools cli再次创建它,但仍然出现相同的错误.我还导出了管理员凭据.

I have tried removing the functions directory and creating it again using the firebase-tools cli but I still get the same error. I have also exported the admin credentials.

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

I'm using the default method created in the index.ts file generated from the firebase-tools cli.

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!");
});

我希望仿真器启动该功能的实例以进行测试,但相反,我看到此错误:

I expect the emulator to spin up instances of the function for testing but instead, I see this error:

✔  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.

If you are experiencing this error, run npm install firebase-functions@3.0.2 in your functions directory.

此问题将很快得到解决,您可以在此处进行以下操作: https://github.com/firebase/firebase-tools/issues/1480

This will be fixed soon, and you can follow along here: https://github.com/firebase/firebase-tools/issues/1480

这篇关于无法在本地测试云功能,模拟器无法以TypeError开头:_onRequestWithOpts不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆