I've started to deploy my cloud function with firebase deploy --only functions:(functionName), but 'deploying' status does not end and it's being deployed infinitely until now. I can't delete it because 'delete' button is disabled while deploying the function.
How to I terminate deploying cloud funtion by force?
Function:
exports.calculate = functions.https.onRequest(async (req, res) => {
const id = (req.query.id).toString();
let flist = (req.query.fIDs).toString();
const ret = await callCalculate(id, flist);
res.json(ret);
});
async function callCalculate() {...}
If you want to delete the function on cloud and bypass the confirmation prompt, you could add “--force” in your deploy command.
firebase deploy --only functions --project --token --force
I certainly hope this helps.
After re-deploying another cloud function, infinite deploying ended with error logs. I think it have been fallen into deadlock status.
Related
I increase time the same way as described in OpenZepplin samples in the test below:
it("should revert claim drawing with 'Android: bad state'", async () => {
const [owner, signer1] = await ethers.getSigners();
let duration = time.duration.seconds(3);
await time.increase(duration);
await truffleAssert.reverts(
android.claimPainting(1),
'Android: bad state'
);
});
And it fails with Error: Invalid JSON RPC response: "". How can i fix it?
time is imported as const { time } = require("#openzeppelin/test-helpers"); + "#openzeppelin/test-helpers": "0.5.15" in package.json.
I also use ethers from hardhat, don't know if this could cause the problem.
You will need to execute Hardhat local node server and try again.
"npx hardhat node"
Hope this works on your side.
Install web3 and the hardhat-web3 plugin.
npm install --save-dev #nomiclabs/hardhat-web3 web3
Then add the following line to your hardhat config
import "#nomiclabs/hardhat-web3";
I got working code on local NodeJs server, then I tried to run same code on Firebase Function and failed.
Here is my code split into 2 files:
// index.js
const functions = require("firebase-functions");
const polly = require("./polly");
exports.pollySynth = functions.https.onCall((req, res) => {
return polly.speak()
});
// polly.js
const AWS = require("aws-sdk");
// Create an Polly client
const Polly = new AWS.Polly({
signatureVersion: "v4",
region: "my-region",
accessKeyId: "keyId,
secretAccessKey: "access key",
});
// Params
const params = {
Text: "Hello world. This is the word of speech!",
OutputFormat: "json",
};
// prettier-ignore
const synthSpeech = function() {
Polly.synthesizeSpeech(params, function(err, res) {
if (err) {
console.log("err", err);
return err;
} else if (res && res.AudioStream instanceof Buffer) {
return res.AudioStream;
}
});
};
module.exports = {speak: synthSpeech};
When trying to deploy this function, I'm getting this error:
Functions deploy had errors with the following functions: pollySynth(us-central1)
I'm not pro coder, so maybe it's just some dumb error in my code.. Please help me :)
That took around half day to solve this issue. The root of the problem was that for some reason, firebase didn't provide detailed error logs. It just said that there is some error in the code.
Only running this command through the command line helped me to understand what's wrong:
firebase functions:log --only pollySynth
I found that command only at StackOverflow, and official documentation didn't mention it.
Log looked this way:
Did you list all required modules in the package.json dependencies?
2021-08-20T12:04:51.823Z ? speechSynth:
Detailed stack trace: Error: Cannot find module 'aws-sdk'
Now I understand that problem is that npm modules was not installed. It worked locally with an emulator, but deploy was throwing an error 🤯
I tried to install aws sdk using commands like this again and again. Tried to add module into package.json manually as well, but nothing worked...
npm install aws-sdk
npm install --save
Then I looked into "node_modules" folder inside the "functions" folder and didn't find that package!
Then I looked at the folder structure installed by default:
- root
- functions
- node modules
- public
It seems like the terminal is running the command on the root folder, and "node_modules" is placed inside the "functions" folder.
So I opened the terminal, moved to the "functions" folder, and installed aws sdk.
cd functions
npm install aws-sdk
And successfully deployed the function!
The next problem was that the function return null. I needed to use a promise to wait for aws server response.
And that code worked for me:
const createSpeech = function() {
return Polly.synthesizeSpeech(params)
.promise()
.then((audio) => {
if (audio.AudioStream instanceof Buffer) {
return audio.AudioStream;
} else {
throw new Error("AudioStream is not a Buffer.");
}
});
};
Now everything works correctly, and I can move to the next steps.
I'm trying to create a cloud function listening to cloudbuilds topic and making an API call to trigger the build. I think I'm missing something in my index.js file (I'm new to Node.js). Can you provide a sample example of a Cloud Function making an API call to the Cloud Build API?
Here is my function:
const request = require('request')
const accessToken = '$(gcloud config config-helper --format='value(credential.access_token)')';
request({
url: 'https://cloudbuild.googleapis.com/v1/projects/[PROJECT_ID]/builds',
auth: {
'bearer': accessToken
},
method: 'POST',
json: {"steps": [{"name":"gcr.io/cloud-builders/gsutil", "args": ['cp','gs://adolfo-test-cloudbuilds/cloudbuild.yaml', 'gs://adolfo-test_cloudbuild/cloudbuild.yaml']}]},
},
module.exports.build = (err, res) => {
console.log(res.body);
});
I was executing the command gcloud config config-helper --format='value(credential.access_token)', copying the token, and putting it as a value to the variable accessToken. But this didn't work for me.
Here is the error: { error: { code: 403, message: 'The caller does not have permission', status: 'PERMISSION_DENIED' } }
I had the same exact problem and I have solved it by writing a small package, you can use it or read the source code.
https://github.com/MatteoGioioso/google-cloud-build-trigger
With this package you can run a pre-configured trigger from cloud build.
You can also extend to call other cloud build API endpoints.
As my understanding cloud build API requires either OAuth2 or a service account. Make sure you gave the right permission to cloud build in the gcp console under IAM. After that you should be able to download the service-account.json file.
I had deployed a firebase cloud function to send a welcome mail when a user signs in for the first time.
In the firebase console, in firebase cloud function log messages, I saw this error message when the function was invoked.
Error Message:
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
Is it not possible to send emails for free using firebase cloud functions? if it is possible, please explain the procedure. (Possiblly with a sample code)
Edit 1:
1. I am currently using nodemailer for sending mail.
2. I am using Gmail as the mail service.
Does sending mail via nodemailer in firebase cloud functions require billing account?
NO, You DO NOT need a billing account to send email via nodmailer using cloud functions.
I was getting the billing error as yours in my cloud function. And I have done 2 simple steps and it's gone.
1. In your gmail account setting, enable Less secure app access to ON
2. Also go to this link and click continue https://accounts.google.com/DisplayUnlockCaptcha .
After doing the above 2 steps, the billing error is gone, and email is sending successfully from the cloud function.
And here is my nodejs code for your refernce:
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'xyzz#gmail.com',
pass: '123'
},
});
exports.sendMail = functions.https.onRequest(async (req, res) => {
const mailOptions = {
from: '"Test." <noreply#firebase.com>',
to: 'xyz#gmail.com'
};
// Building Email message.
mailOptions.subject = 'Thanks and Welcome!'
mailOptions.text = 'Thanks you for subscribing to our newsletter. You will receive our next weekly newsletter.'
try {
await mailTransport.sendMail(mailOptions);
console.log('subscription confirmation email sent to');
return res.send('Sended');
} catch (error) {
console.error('There was an error while sending the email:', error);
return res.send(error.toString());
}
});
You can test locally before you deploy it
firebase serve --only functions
you will get a link http://localhost:5000/project-name/us-central1/sendMail; paste it in the browser and the cloud function will run. If any errors it will show up in the browser and console/powershell
I maked follow:
feathers g app # with socket and rest
feathers g service # todos & NeDB
npm start
and simple client for this. I copy code from documentation
https://docs.feathersjs.com/api/client/socketio.
const feathers = require('#feathersjs/feathers');
const socketio = require('#feathersjs/socketio-client');
const io = require('socket.io-client');
const socket = io('http://localhost:3030');
const app = feathers();
app.configure(socketio(socket));
app.service('todos')
.on('created', message => console.log('New message created', message));
app.service('todos').find().then(r => {
console.log(r)
}).catch(e => console.log('error',e))
app.service('todos').create({
title: 'A message from a REST client'
});
this client code get me timeout errors for find() and create() methods
But if I make POST request by CURL, I have onCreated message in console
Why I got errors on create() and find() calls?
UPDATE:
I maked git repo for easy reproduce this problem
https://github.com/tolyanor/feathersjs-error
UPDATE2:
I change autogenerated file src/app.js like in feathers example chat application https://github.com/feathersjs/feathers-chat/blob/master/src/app.js
Now I CAN call service method create on client, but CAN NOT receive onCreated message. So, this code
app.service('/todos')
.on('created', message => console.log('New todos created', message));
never calling
You are using a Feathers v3 client with a Feathers v2 server. Old clients will be backwards compatible with new servers but not the other way around. Follow the migration guide to upgrade your server or generate a new application using #feathersjs/cli (feathers --version on the command line should show v3.5.0 or later).