首页 > 解决方案 > TypeError:_onRequestWithOpts 不是 Object.httpsProvider._onRequestWithOpts 的函数

问题描述

我正在创建一个使用 firebase 功能的应用程序。我创建了我的应用程序目录并运行了 firebase init。完成后,我尝试运行它为您提供的使用 firebase serve 的 hello world 程序,但出现此错误:

TypeError: _onRequestWithOpts is not a function
at Object.httpsProvider._onRequestWithOpts

从它的样子来看,这似乎是 onRequest() 方法的一个问题,但我之前已经使用它制作了应用程序并且从未遇到过这个问题。我实际上并没有更改他们最初给您的任何代码,因此除非他们决定在一夜之间更改某些内容,否则我不确定问题是什么。

使用 firebase deploy 可以,但 firebase serve 不行。使用 express 并添加新功能,运行 firebase deploy 和 serve 时会弹出错误。

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)

标签: firebasegoogle-cloud-functionsfirebase-cli

解决方案


推荐阅读