1

Running a Node.js function in the local Firebase server does not result in the error below, but when I do firebase deploy and try to run the same function on the deployed server I get this error in the Firebase Functions log (in the web Firebase console):

Error: Cannot find module '@google-cloud/speech'

What have I missed? (I can run some other functions on the deployed server, but I am new to this and have no idea if I have done something different, or if there is something different about this npm module.)

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Leo
  • 4,136
  • 6
  • 48
  • 72
  • 1
    What does your package.json look like? Have you installed that module? – Doug Stevenson Mar 24 '18 at 00:18
  • @DougStevenson Hm, good question. I can't find the package in package.json, but I believe I have installed it. I have done `npm install --save @google-cloud/speech` as the instructions say. I just did it once more just to be sure. And. That fixed the problem. It looks like I did not run the install from the `functions` directory before. (And I don't understand what happened in the local web server case then.) Many thanks. – Leo Mar 24 '18 at 01:24
  • @DougStevenson Do you want to add the answer? Or should I do it? – Leo Mar 24 '18 at 01:25

1 Answers1

1

Cloud Functions will only install the modules that you've declared as dependencies in your package.json (and their dependencies) in the functions folder. If the module doesn't show up there, you won't be able to access it directly from your code. Be sure to run @google-cloud/speech from your functions folder, so that you can use it both during development an when deployed.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks. I still do not understand how to activate `@google-cloud/speech` on the local dev server, but that is another question, I believe. – Leo Mar 24 '18 at 17:35
  • Typically a module doesn't do anything until you start writing code that accesses it. – Doug Stevenson Mar 24 '18 at 18:33
  • :-) That is my experience too. I have posted a new question: https://stackoverflow.com/questions/49471143/activating-google-speech-api-in-firebase-cli – Leo Mar 24 '18 at 23:49