I have the following code:
exports = function(changeEvent) {
var {PubSub} = require("@google-cloud/pubsub");
var avro = require("avro-js");
const keyFilename = context.values.get("GOOGLE_APPLICATION_CREDENTIALS")
const projectId = "<project_name>"
const pubSubClient = new PubSub({projectId, keyFilename});
const topicName = "<topic_name>"
const topic = pubSubClient.topic(topicName);
try {
const data = "something";
const dataBuffer = Buffer.from(data);
return topic.publish(dataBuffer)
.then((messageId) => console.log(`Message ${messageId} published.`))
.catch((err) => console.log(`Error publishing message: ${err}`));
} catch(err) {
console.log("Error: ", err.message);
}
};
When running the above it returns back the following:
Error publishing message: FunctionError: TypeError: 'createReadStream' is not a function
> result:
{
"$undefined": true
}
> result (JavaScript):
EJSON.parse('{"$undefined":true}')
Something to point out:
- I am not the first to encounter this problem but both of the threads did not receive much attention
- The GOOGLE_APPLICATION_CREDENTIALS value ought to be a path to the secret called service-account.. it's a json of a service account key from GCP. What confuses me though is that if I console.log the path it prints out the secret as json and not the path to the secret

At this point I am not sure what it can be. At first I thought it could be a async vs sync problem. But I tried both approaches resulting in the same error. Another problem could be the authentication with the client. But the error message does not provide me with much and when searching for createReadStream I can't find anything useful.