cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

ERROR: TypeError: google.discoverAPI is not a function on functions start

Open davidwallen opened this issue 5 years ago • 31 comments

Host: Pixelbook Slate i7 16 GB Host OS: Google Chrome OS Version 72.0.3626.122 (Official Build) (64-bit) Container OS: Linux penguin 4.19.4-02480-gd44d301822f0 #1 SMP PREEMPT Thu Dec 6 17:45:27 PST 2018 x86_64 GNU/Linux Virtual machine info:

  • memory: 10GiB System memory
  • processor: 06/8e

node --version: v8.15.1 npm --version: 6.4.1 functions --version: 1.0.0-beta.5 reproduced by: user:~/cloud-functions-emulator$ functions start output:

Google Cloud Functions Emulator RUNNING
ERROR: TypeError: google.discoverAPI is not a function
    at Promise (/home/davidwallen/cloud-functions-emulator/src/client/rest-client.js:112:14)
    at new Promise (<anonymous>)
    at RestClient.getService (/home/davidwallen/cloud-functions-emulator/src/client/rest-client.js:104:12)
    at RestClient._action (/home/davidwallen/cloud-functions-emulator/src/client/rest-client.js:31:17)
    at RestClient.listFunctions (/home/davidwallen/cloud-functions-emulator/src/client/rest-client.js:145:17)
    at Controller.list (/home/davidwallen/cloud-functions-emulator/src/cli/controller.js:521:24)
    at controller.doIfRunning.then (/home/davidwallen/cloud-functions-emulator/src/cli/commands/list.js:72:28)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)

davidwallen avatar Mar 25 '19 19:03 davidwallen

I'm having exact the same problem after a nvm and node upgrading and reinstalled firebase-tools.

@davidwallen have you solved it?

bluet avatar Apr 17 '19 04:04 bluet

I had the same earlier today. I solved it by some combination of reinstalling the gcloud sdk, upgrading node, and accepting a pop-up from Mac granting network access to Node (they happened at approximately the same time, so I wasn’t able to narrow it down)

kmcnellis avatar Apr 17 '19 04:04 kmcnellis

1.0.0-beta.6.0 released before couple hours ago. after that could not deploy a function to my local project. https://www.npmjs.com/package/@google-cloud/functions-emulator/v/1.0.0-beta.6.0

In workaround I've fixed the issue can not launch functions-emulaor from firebase-tools as bellow:

npx functions stop
rm -rf ./node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator
npm i "@google-cloud/functions-emulator"@"1.0.0-beta.5
npx firebase functions:shell

laiso avatar Apr 17 '19 05:04 laiso

thanks @laiso, I hope google finds a way to solve this

roynes avatar Apr 17 '19 09:04 roynes

@laiso pointed me to the right direction but in my case I had to downgrade a version lower than him. Downgraded to @google-cloud/functions-emulator"@1.0.0-beta.4 and after solving another, unrelated error, it worked.

If you downgrade to beta.4 and encounter the "RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. " error, I got it to work applying this hack: Issue #770

rschpdr avatar Apr 17 '19 13:04 rschpdr

@laiso recommendation fixed it for me too, but i had to run it in my global npm repository ! :)

clementdevos avatar Apr 17 '19 13:04 clementdevos

OK. I was able to reproduce this error by following the quickstart in the README.md. I'm not sure of the issue, but I'm guessing there's a problem with the Google API Client dependency.

https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/6dbd88345f6f7d129644d2547d949aaf36897fd0/src/client/rest-client.js#L112

grant avatar Apr 17 '19 15:04 grant

Was using [email protected] but got the same issue with older verions solved this using:

  1. NODEV="$(node -v)" && rm -rf ~/.nvm/versions/node/$NODEV/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator
  2. npm i -g @google-cloud/[email protected]
  3. NODEV="$(node -v)" && cp -R ~/.nvm/versions/node/$NODEV/lib/node_modules/@google-cloud/functions-emulator ~/.nvm/versions/node/$NODEV/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator

HugoGresse avatar Apr 17 '19 16:04 HugoGresse

1.0.0-beta.6 has been unpublished. Can you try installing the Firebase CLI an trying again for that issue?

Note that this issue still exists with this GitHub repo.

grant avatar Apr 17 '19 19:04 grant

@grant I can confirm it works now.

[2019-04-17T19:22:54.820Z] ----------------------------------------------------------------------
[2019-04-17T19:22:54.824Z] Command:       /home/bluet/.nvm/versions/node/v10.15.0/bin/node /home/bluet/.nvm/versions/node/v10.15.0/bin/firebase serve --debug
[2019-04-17T19:22:54.825Z] CLI Version:   6.6.0
[2019-04-17T19:22:54.825Z] Platform:      linux
[2019-04-17T19:22:54.825Z] Node Version:  v10.15.0
[2019-04-17T19:22:54.825Z] Time:          Thu Apr 18 2019 03:22:54 GMT+0800 (GMT+08:00)
[2019-04-17T19:22:54.826Z] ----------------------------------------------------------------------

Though not sure why it stuck at Parsing function triggers for several minutes every time I run firebase server --debug command. This didn't happen utill yesterday I did npm upgrade.

bluet avatar Apr 17 '19 19:04 bluet

[2019-04-17T20:11:10.027Z] ---------------------------------------------------------------------- [2019-04-17T20:11:10.043Z] Command: C:\Program Files\nodejs\node.exe C:\Users\Luke\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js functions:shell --debug [2019-04-17T20:11:10.043Z] CLI Version: 6.6.0 [2019-04-17T20:11:10.043Z] Platform: win32 [2019-04-17T20:11:10.043Z] Node Version: v8.11.2 [2019-04-17T20:11:10.043Z] Time: Wed Apr 17 2019 13:11:10 GMT-0700 (Pacific Daylight Time) [2019-04-17T20:11:10.043Z] ---------------------------------------------------------------------- .. .. [2019-04-17T20:11:14.378Z] Error while deploying to emulator: TypeError: google.discoverAPI is not a function TypeError: google.discoverAPI is not a function

LVeach avatar Apr 17 '19 20:04 LVeach

@LVeach did you uninstall and install firebase-tools again in the past 2 hours? If not, please try it, as @grant mentioned in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-484225232 that he unpublished the latest (beta 6, w/ bug) version so you'll have the stable one back now.

bluet avatar Apr 17 '19 21:04 bluet

@BlueT I thought I had, but I will attempt those steps again!

LVeach avatar Apr 17 '19 21:04 LVeach

@LVeach if you still have the same issue, please paste your steps and the output of functions start debug info, so they can help you further. :-)

bluet avatar Apr 17 '19 21:04 bluet

@BlueT Absolutely, I am currently doing a clean install and then will re-apply the steps above and see where it's at

LVeach avatar Apr 17 '19 21:04 LVeach

@BlueT @grant : blowing away my global yarn cache along with the above steps got me back in business, thank you very much for the pointers in this thread!

LVeach avatar Apr 17 '19 22:04 LVeach

Same issue with latest commit.

On one side we need node 8 to get async/await in our functions code and on the other we cant use node 8 on GoogleCloudPlatform/cloud-functions-emulator.

gregtap avatar Apr 19 '19 15:04 gregtap

@coulix My projects use node 8 and node 10 in local test environments and they work fine, so don't worry. :smiley:

At the time you post comment, the latest commit is https://github.com/GoogleCloudPlatform/cloud-functions-emulator/commit/098e253188d8caa706da08350483468d60f0c049, which is before the problem get solved.
As mentioned in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-484225232 , DON'T use latest commit on github. Instead, please use npm to install it.
And as mentioned in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-484272701 , please uninstall and reinstall.

bluet avatar Apr 19 '19 17:04 bluet

@BlueT I am trying

nvm current v8.16.0

npx functions --version 1.0.0-beta.5

I used yarn install git://github.com/GoogleCloudPlatform/cloud-functions-emulator.git


i  functions: Preparing to emulate functions.
i  hosting: Serving hosting files from: prod/client
✔  hosting: Local server: http://localhost:3000
⚠  functions: Failed to emulate nuxtssr
⚠  functions: Failed to emulate func
i  functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
^CShutting down...

 ~/code/perso/nuxt2-ssr-firebase   feature/test ● ?  npx functions start                              SIGINT(2) ↵  10032  21:27:04
Google Cloud Functions Emulator RUNNING
ERROR: TypeError: google.discoverAPI is not a function
    at Promise (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:112:14)
    at new Promise (<anonymous>)
    at RestClient.getService (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:104:12)
    at RestClient._action (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:31:17)
    at RestClient.listFunctions (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:145:17)
    at Controller.list (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:521:24)
    at controller.doIfRunning.then (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/cli/commands/list.js:72:28)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)````

gregtap avatar Apr 19 '19 19:04 gregtap

@BlueT I am trying

nvm current v8.16.0

npx functions --version 1.0.0-beta.5

I used yarn install git://github.com/GoogleCloudPlatform/cloud-functions-emulator.git


i  functions: Preparing to emulate functions.
i  hosting: Serving hosting files from: prod/client
✔  hosting: Local server: http://localhost:3000
⚠  functions: Failed to emulate nuxtssr
⚠  functions: Failed to emulate func
i  functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
^CShutting down...

 ~/code/perso/nuxt2-ssr-firebase   feature/test ● ?  npx functions start                              SIGINT(2) ↵  10032  21:27:04
Google Cloud Functions Emulator RUNNING
ERROR: TypeError: google.discoverAPI is not a function
    at Promise (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:112:14)
    at new Promise (<anonymous>)
    at RestClient.getService (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:104:12)
    at RestClient._action (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:31:17)
    at RestClient.listFunctions (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/client/rest-client.js:145:17)
    at Controller.list (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:521:24)
    at controller.doIfRunning.then (/Users/greg/code/perso/nuxt2-ssr-firebase/node_modules/@google-cloud/functions-emulator/src/cli/commands/list.js:72:28)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)````

gregtap avatar Apr 19 '19 19:04 gregtap

@coulix did you try npm i @google-cloud/[email protected] ? AFAIK, and as replied in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-484962520 and other comments listed in that comment, DON'T install from this git repo directly until @grant has further fixes.

@grant I noticed that 1.0.0-beta.6 is listing on npm again since a day ago, but I can't see any fix. Did you intend to publish the same buggy version or by mistake?

bluet avatar Apr 20 '19 02:04 bluet

The beta 6 update just removes the Node 6 warning so the Firebase CLI won't show the warning either. This was a request by the Firebase CLI team.

grant avatar Apr 20 '19 03:04 grant

Ok I did functions stop, uninstall then installed the pinned beta.5 branch. I am making progress.


i  functions: Preparing to emulate functions.
i  hosting: Serving hosting files from: prod/client
✔  hosting: Local server: http://localhost:3000
⚠  functions: Failed to emulate nuxtssr
⚠  functions: Failed to emulate func
error: {
    code: 404,
    status: "NOT_FOUND",
    message: "Function nuxtssr in location us-central1 in project nuxt-test-96b4a does not exist",
    errors: [
        "Function nuxtssr in location us-central1 in project nuxt-test-96b4a does not exist"
    ]
  }
}

gregtap avatar Apr 21 '19 08:04 gregtap

@coulix can you provide a demo repo to reproduce your issue? I think that would help people on investigating where the problem is.

bluet avatar Apr 22 '19 09:04 bluet

I have it here https://github.com/coulix/nuxt2-ssr-firebase

yarn setup
yarn serve

https://nuxt-test-96b4a.firebaseapp.com/

Renderer is loaded but not all resources are unavailable! Please check /srv/nuxt/dist/server existence.

https://github.com/nuxt/nuxt.js/issues/5549

gregtap avatar Apr 22 '19 11:04 gregtap

@coulix I've checked the repo you provide and followed your steps, it installed 1.0.0-beta.6.

You can check it by $ cat node_modules/@google-cloud/functions-emulator/package.json |grep version which shows "version": "1.0.0-beta.6",.

The reason is, you specified version ^1.0.0-beta.5, which the ^ will install latest compatible version of @google-cloud/functions-emulator.

  "dependencies": {
    "@google-cloud/functions-emulator": "^1.0.0-beta.5"
  }

And due to @grant published broken version 1.0.0-beta.6 again (mentioned in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-485050265 and https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-485053860), you will get the broken 1.0.0-beta.6 installed in your system.


After npm i @google-cloud/[email protected] and those setup processes, I can get it running.

bluet@Zorya:~/workspace/tmp/nuxt2-ssr-firebase$ NODE_ENV=development firebase serve   --only functions,hosting -p 3000 --project test-cf2e8

=== Serving from '/home/bluet/workspace/tmp/nuxt2-ssr-firebase'...

i  functions: Preparing to emulate functions.
Warning: You're using Node.js v10.15.3 but Google Cloud Functions only supports v6.11.5.
i  hosting: Serving hosting files from: prod/client
✔  hosting: Local server: http://localhost:3000
✔  functions: nuxtssr: http://localhost:3001/test-cf2e8/us-central1/nuxtssr
✔  functions: func: http://localhost:3001/test-cf2e8/us-central1/func

And these messages showed when requesting http://localhost:3000/ doesn't belong to cloud-functions-emulator. You should check your nuxt2 project itself.

[hosting] Rewriting / to local function nuxtssr
info: User function triggered, starting execution
info: IN New Nuxt Trial: 
error: 
03:13:59  ERROR  Renderer is loaded but not all resources are unavailable! Please check /home/bluet/workspace/tmp/nuxt2-ssr-firebase/prod/server/nuxt/dist/server existence.

  at VueRenderer.renderRoute (node_modules/@nuxt/vue-renderer/dist/vue-renderer.js:2817:19)
  at Server.renderRoute (node_modules/@nuxt/server/dist/server.js:811:38)
  at nuxtMiddleware (node_modules/@nuxt/server/dist/server.js:124:26)
  at call (node_modules/connect/index.js:239:7)
  at next (node_modules/connect/index.js:183:5)
  at servePlaceholderMiddleware (node_modules/serve-placeholder/src/index.js:29:16)
  at call (node_modules/connect/index.js:239:7)
  at next (node_modules/connect/index.js:183:5)
  at next (node_modules/connect/index.js:161:14)
  at node_modules/@nuxt/server/dist/server.js:555:5

info: Execution took 23 ms, user function completed successfully
127.0.0.1 - - [23/Apr/2019:19:13:59 +0000] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/73.0.3683.86 Chrome/73.0.3683.86 Safari/537.36"

Because I didn't see anything in that folder.

$ LC_ALL=C ls /home/bluet/workspace/tmp/nuxt2-ssr-firebase/prod/server/nuxt/dist/server
ls: cannot access '/home/bluet/workspace/tmp/nuxt2-ssr-firebase/prod/server/nuxt/dist/server': No such file or directory

bluet avatar Apr 23 '19 19:04 bluet

I just realized that what mentioned in https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/321#issuecomment-485053860 is that the new beta.6 doesn't break things. So it's ok to have beta.6 installed. Sorry for misunderstanding you @grant

@coulix I've tested your repo and it seems to be problems with your nuxt project itself.

bluet avatar Apr 23 '19 20:04 bluet

@BlueT Thank you so much for the investigation! I will pursue this bug onto Nuxt then.

gregtap avatar Apr 24 '19 06:04 gregtap

I'm using beta 6 and have the same error by running yarn serve, which is a composition of npm run build && firebase serve --only functions.

Running those 2 commands separately works.

JFGHT avatar Apr 25 '19 12:04 JFGHT

Hi! I try to debug firestore functions locally and get the same error. (use nvm, windows 10 and example functions "makeUppercase").

`firebase --debug functions:shell [2019-04-26T08:41:30.933Z] ---------------------------------------------------------------------- [2019-04-26T08:41:30.937Z] Command: C:\Program Files\nodejsnvm\node.exe C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js --debug functions:shell [2019-04-26T08:41:30.938Z] CLI Version: 6.6.0 [2019-04-26T08:41:30.938Z] Platform: win32 [2019-04-26T08:41:30.938Z] Node Version: v8.16.0 [2019-04-26T08:41:30.939Z] Time: Fri Apr 26 2019 11:41:30 GMT+0300 (Russia TZ 2 Standard Time) [2019-04-26T08:41:30.939Z] ----------------------------------------------------------------------

[2019-04-26T08:41:30.950Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] [2019-04-26T08:41:30.951Z] > authorizing via signed-in user ... [2019-04-26T08:41:34.891Z] Starting @google-cloud/functions-emulator [2019-04-26T08:41:34.936Z] Parsing function triggers [2019-04-26T08:41:35.279Z] Deploying functions locally [2019-04-26T08:41:35.287Z] Error while deploying to emulator: TypeError: google.discoverAPI is not a function TypeError: google.discoverAPI is not a function at Promise (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules@google-cloud\functions-emulator\src\client\rest-client.js:112:14) at new Promise () at RestClient.getService (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules@google-cloud\functions-emulator\src\client\rest-client.js:104:12) at RestClient._action (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules@google-cloud\functions-emulator\src\client\rest-client.js:31:17) at RestClient.getFunction (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules@google-cloud\functions-emulator\src\client\rest-client.js:132:17) at Controller.deploy (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules@google-cloud\functions-emulator\src\cli\controller.js:389:24) at C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\lib\functionsEmulator.js:153:18 at arrayMap (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\lodash\lodash.js:639:23) at Function.map (C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\lodash\lodash.js:9556:14) at C:\Users\briza\AppData\Roaming\npm\node_modules\firebase-tools\lib\functionsEmulator.js:131:26 ! functions: Failed to emulate makeUppercase i functions: No functions to emulate. No functions emulated.`

alex89607 avatar Apr 26 '19 08:04 alex89607