我正在创建一个使用firebase功能的应用程序。我创建了我的应用程序目录并运行了firebase init。完成之后,我尝试运行hello world程序,该程序使用firebase serve为您提供程序,但出现此错误:
TypeError: _onRequestWithOpts is not a function
at Object.httpsProvider._onRequestWithOpts
从外观上看,似乎是onRequest()方法的问题,但是我之前使应用程序使用过此方法,但从未遇到过此问题。我实际上并没有更改他们最初给您的代码,因此除非他们决定在一夜之间更改某些内容,否则我不确定是什么问题。
使用Firebase部署可正常运行,但Firebase服务则不能。使用express和添加新功能时,运行Firebase部署和服务时会弹出错误。
const functions = require('firebase-functions');
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-
functions
//
exports.helloWorld = functions.https.onRequest((request, response)
=> {
response.send("Hello from Firebase!");
});
Gabriels-MacBook-Pro:functions Mike$ firebase serve
=== Serving from '/Users/Gabe/Desktop/mycart-functions'...
⚠ Your requested "node" version "8" doesn't match your global
version "10"
✔ functions: Emulator started at http://localhost:5000
i functions: Watching "/Users/Gabe/Desktop/mycart-
functions/functions" for Cloud Functions...
⚠ 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> (/Users/Gabe/Desktop/mycart-
functions/functions/index.js:6:39)
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)