I am trying to deploy a Google Cloud function, I started by just adding the initial requirements to my index.js file:
// Import the Google Cloud client libraries
const nl = require('@google-cloud/language')();
const speech = require('@google-cloud/speech')();
const storage = require('@google-cloud/storage')();
But I get the following message when deploying:
Detailed stack trace: TypeError: require(...) is not a function
This only happens with the @google-cloud/speech and @google-cloud/language modules, the @google-cloud/storage module is loaded fine as a function (I tested by commenting the first two).
Any advise will be greatly appreciated.
Borrigan
By essence Cloud Functions are implementing a serverless architecture: they don't run all the time (i.e. permanently), but when they are triggered.
There are two types of Cloud Functions: HTTP functions, which handle HTTP requests and use HTTP triggers. See Write HTTP functions for information about implementing HTTP functions. Event-driven functions, which handle events from your cloud environment and use event triggers as described in Cloud Functions triggers.
By default each Cloud Run container instance can receive up to 80 requests at the same time; you can increase this to a maximum of 1000.
onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.
With reference to this Github comment, there was some changes in google-cloud
v2 package
so you import packages such as:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
// config...
});
Google cloud function are nodejs modules so the syntax is same as nodejs syntax.
Regarding your problem:
you have to write
const storage = require('@google-cloud/storage');
(without () at the end of each statement)
So the correct declaration will be:
// Import the Google Cloud client libraries
const nl = require('@google-cloud/language');
const speech = require('@google-cloud/speech');
const storage = require('@google-cloud/storage');
I hope this helps.
It tells you that whatever you required is not a function and therefore can't be invoked with ()
if you look here : https://www.npmjs.com/package/@google-cloud/language#using-the-client-library you see a service object with multiple class returning functions is being returned, so you should set it up like this:
const nl = require('@google-cloud/language');
const language = new nl.LanguageServiceClient();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With