Can't test cloud functions locally, emulator fails to start with TypeError: _onRequestWithOpts is not a function

给你一囗甜甜゛ 提交于 2019-12-06 19:46:01

问题


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.

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

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.

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.

回答1:


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

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




回答2:


I found error in:

node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js

line 276:

const _onRequestWithOpts = httpsProvider._onRequestWithOpts;

should be:

const _onRequestWithOpts = httpsProvider._onRequestWithOptions;



回答3:


Downgrade firebasefunction to version 3.0.0




回答4:


Delete node_modules then run npm install, npm install firebase-admin and npm install firebase-functions@3.0.2



来源:https://stackoverflow.com/questions/56947574/cant-test-cloud-functions-locally-emulator-fails-to-start-with-typeerror-onr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!