Function deployment hangs at "all necessary APIs are enabled" - node.js

When deploying the Cloud Functions to the Firebase Cloud, they take a very long time right after the log "functions: all necessary APis are enabled".
I am deploying 6 functions.
I am using node 10 since using node 8 in combination with the URL module caused some errors that went away using node 10.
the package.json:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"babel-eslint": "^10.0.1",
"cheerio": "^1.0.0-rc.2",
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.3.0",
"lighthouse": "^5.1.0",
"ping": "^0.2.2",
"puppeteer": "^1.17.0",
"puppeteer-extra": "^2.1.3",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"url": "^0.11.0"
},
"devDependencies": {
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1"
},
"engines": {
"node": "10"
},
"private": true
}
The deployment used to go much faster, but recently it started behaving differently.
I dont know when excactly it happened.
My questions are:
Does anyone know what the issue might be?
If no, does anyone know how I would go about 'debugging' this issue?
Thank you.

Related

VS Code Unbound breakpoints: We couldn't find a corresponding source location

Trying to debug nodejs typescript files while running firebase emulators. However, breakpoints are unbounded so even though the debugger starts and attaches to port 9229 breakpoints are not getting hit. Below are my vscode settings and tsconfig, etc.
Anyone running firebase emulators run into this issue trying to debug in vscode? I'm running VS Code Version: 1.75.0.
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"noImplicitAny": false,
"strictNullChecks": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"compileOnSave": true,
"include": ["src", "index.ts"]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"port": 9229,
"trace": true
}
]
}
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"dev": "cd ~/AndroidStudioProjects/order_fulfillment && firebase emulators:start --import=saved-data --export-on-exit && tsc --watch",
"debug": "cd ~/AndroidStudioProjects/order_fulfillment && firebase emulators:start --import=saved-data --export-on-exit --inspect-functions && tsc --watch",
"deploy": "cd functions && npm ci && npm run build && cd .. && firebase deploy --only hosting",
"web": "cd ~/AndroidStudioProjects/order_fulfillment && flutter run -d chrome --web-renderer canvaskit --web-hostname localhost --web-port 45887",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"#elastic/elasticsearch": "^8.2.1",
"#google-cloud/pubsub": "^2.15.1",
"#google-cloud/secret-manager": "^3.7.1",
"#sendgrid/mail": "^7.6.0",
"#shopify/shopify-api": "^5.0.1",
"aws-sdk": "^2.1231.0",
"axios": "^0.27.2",
"body-parser": "^1.19.2",
"cors": "^2.8.5",
"csvtojson": "^2.0.10",
"eslint": "^8.23.0",
"express": "^4.17.2",
"firebase-admin": "^11.0.1",
"firebase-functions": "^4.2.1",
"html-pdf-node": "^1.0.8",
"luxon": "^1.27.0",
"node-fetch": "^2.6.7",
"pdf-merger-js": "^4.1.0",
"qrcode": "^1.5.1",
"uuid": "^8.3.2"
},
"devDependencies": {
"#types/download": "^8.0.1",
"#types/html-pdf": "^3.0.0",
"#types/luxon": "^1.27.0",
"#types/mime-types": "^2.1.1",
"#types/node-fetch": "^2.6.1",
"#types/pdfkit": "^0.12.6",
"#types/qrcode": "^1.5.0",
"#types/request": "^2.48.7",
"#typescript-eslint/eslint-plugin": "^5.12.0",
"#typescript-eslint/parser": "^5.12.0",
"concurrently": "^7.4.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^4.2.1",
"firebase-functions-test": "^0.2.0",
"node": "^18.8.0",
"prettier": "^2.7.1",
"typescript": "^4.5.4"
},
"private": true,
"version": "1.0.0",
"author": "",
"license": "ISC",
"description": ""
}
I added trace to launch.json and opened the vscode debug file at https://microsoft.github.io/vscode-pwa-analyzer/index.html and this is an example of what the logs show for the unbounded breakpoint.
VS Code Debug Log Viewer Example
As you can see in screenshot, TS is getting compiled correctly to the outDir so there should not be any issues with mapping.
Screenshot demonstrating tsc is building to lib directory.
I have reached out to vscode support, but they are suggesting it is not vscode and some kind of issue with firebase setup? However, all my emulators are running just fine and I am able to do everything, but set a breakpoint and debug.
I think you need to set the outFiles attribute in your launch.json file. See the VS Code docs on TypeScript debugging > Mapping the output location:
If generated (transpiled) JavaScript files do not live next to their source, you can help the VS Code debugger locate them by setting the outFiles attribute in the launch configuration. Whenever you set a breakpoint in the original source, VS Code tries to find the generated source by searching the files specified by glob patterns in outFiles.
I'm not sure exactly what value you need to use for the setting, but I suspect its something based on the value of your outDir setting in your tsconfig.json, perhaps with a trailing /**/*.js (or perhaps not). If this works for you, suggest an edit to this answer with the exact value that you got to work.

Use Node-Fetch in TypeScript with CloudFunctions

So Im using Cloud Functions from Firebase with TypeScript
I want to import node-fetch like:
import * as fetch from "node-fetch";
but it doesn't import correctly:
when I try to use fetch like this:
fetch("https://payments.sandbox.braintree-api.com/graphql", {
method: "POST",
headers: {
"Authorization":
"bnIzdm5nZHlqempjNnQ3bTo0ZjMxYjQ5YjA2MDNjN2RkMjZhM2UyMGE3M2E3MWVlNw==",
"Braintree-Version": "2022-08-13",
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
}),
})
I get following problem:
This expression is not callable.
Type 'typeof import(".../node_modules/node-fetch/#types/index")' has no call signatures.
I was wondering whether I need to add a dependency after running:
npm install node-fetch
because in my package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^5.12.0",
"#typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.5.4"
},
"private": true
}
there is no node-fetch dependency
if this is the case how can I fix my problem?
As mentioned here, you have to add this dependency explicitly in the package.json, as node-fetch is not a built-in module and will need installation.
You can run npm install node-fetch on your local machine, but the Cloud Functions deploy doesn't work this way.
HTH, else let me know.

Vue.js app is showing loading blank screen hosted on firebase

I am actually a flutter developer and have configured an existing project whose admin panel is built in VUE.js and mobile app is built in flutter. I have configured this app many times for clients but can't do it for the last time.
This hosted VUE.app is making problem and this is not. Both's code are same except some of the library changes however both were deployed with some of the deprecation warnings to firebase ( I will provide those warnings if necessary).
Admin panel has two parts i.e BACKEND & FRONTEND
Backend:
Index.js where the api cloud function lies which is deployed on firebase-functions.
const functions = require('firebase-functions');
const api = require('./src/api');
const runtimeOpts = {
timeoutSeconds: 300,
memory: '1GB',
};
exports.api = functions
.runWith(runtimeOpts)
.https.onRequest(api);
And this is the api's index being called from above index.js
const express = require('express');
const cors = require('cors');
const app = express();
const authFirebaseService = require('../auth/authFirebaseService');
const authMiddleware = require('../auth/authMiddleware');
const {
init: databaseInit,
middleware: databaseMiddleware,
} = require('../database/databaseInit');
const bodyParser = require('body-parser');
databaseInit().catch((error) => console.error(error));
authFirebaseService.init();
app.use(databaseMiddleware);
app.use(authMiddleware);
app.use(bodyParser.json());
app.use(cors({ origin: true }));
const routes = express.Router();
require('./auditLog')(routes);
require('./auth')(routes);
require('./iam')(routes);
require('./settings')(routes);
require('./customers')(routes);
require('./suppliers')(routes);
require('./staff')(routes);
require('./products')(routes);
require('./brands')(routes);
require('./categories')(routes);
require('./expenses')(routes);
require('./expenseCategory')(routes);
require('./assets')(routes);
require('./devices')(routes);
require('./notice')(routes);
require('./sales')(routes);
require('./purchases')(routes);
require('./returns')(routes);
require('./stockAdjustments')(routes);
require('./units')(routes);
require('./giftCard')(routes);
require('./coupon')(routes);
require('./damages')(routes);
require('./leave')(routes);
require('./leaveType')(routes);
require('./allowanceAndDeduction')(routes);
require('./payroll')(routes);
require('./attendance')(routes);
require('./taxClass')(routes);
require('./todo')(routes);
require('./documents')(routes);
require('./paymentMethods')(routes);
require('./documentTypes')(routes);
require('./memos')(routes);
require('./currency')(routes);
require('./holiday')(routes);
require('./stall')(routes);
require('./variation')(routes);
require('./productLogs')(routes);
require('./stockTransfer')(routes);
require('./deviceSessions')(routes);
require('./productCount')(routes);
require('./productValue')(routes);
require('./register')(routes);
require('./commissions')(routes);
require('./transactions')(routes);
require('./priceChange')(routes);
app.use('/api', routes);
module.exports = app;
package.json:
{
"name": "app-backend",
"description": "Backend",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "nodemon ./server.js",
"logs": "firebase functions:log",
"test": "nodemon --exec 'cross-env NODE_ENV=test mocha ./src/**/*.test.js --exit || exit 1'",
"predeploy:development": "firebase use development && firebase functions:config:set env.value=\"development\"",
"deploy:development": "firebase deploy --only functions",
"deploy:appengine:development": "gcloud app deploy app-engine.development.yaml --project <insert project id here>",
"predeploy:production": "firebase use production && firebase functions:config:set env.value=\"production\"",
"deploy:production": "firebase deploy --only functions",
"deploy:appengine:production": "gcloud app deploy app-engine.production.yaml --project <insert project id here>"
},
"dependencies": {
"cors": "2.8.5",
"express": "4.16.4",
"firebase-admin": "7.0.0",
"firebase-functions": "2.2.0",
"graphql": "14.1.1",
"graphql-fields": "2.0.1",
"graphql-iso-date": "3.6.1",
"graphql-tools": "4.0.4",
"graphql-type-json": "0.2.1",
"lodash": "^4.17.15",
"moment": "2.24.0",
"nodemailer": "5.1.1"
},
"engines": {
"node": "16"
},
"private": true,
"devDependencies": {
"cross-env": "5.2.0",
"firebase-functions-test": "0.1.6",
"mocha": "^6.2.2",
"node-mocks-http": "1.7.3",
"nodemon": "1.18.10"
},
"version": "1.0.0",
"main": "index.js",
"author": "Bilal Saeed",
"license": "ISC"
}
Frontend:
package.json
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "npm run start:localhost",
"start:localhost": "vue-cli-service serve --mode localhost --port 8081",
"build:localhost": "vue-cli-service build --mode localhost",
"start:development": "vue-cli-service serve --mode development --port 8081",
"build:development": "vue-cli-service build --mode development",
"deploy:development": "firebase use development && npm run build:development && firebase deploy --only hosting,storage",
"start:production": "vue-cli-service serve --mode production --port 8081",
"build:production": "vue-cli-service build --mode production",
"deploy:production": "firebase use production && npm run build:production && firebase deploy --only hosting,storage",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.0",
"chart.js": "2.7.3",
"element-ui": "2.5.4",
"file-saver": "2.0.1",
"filesize": "4.1.2",
"firebase": "^9.9.1",
"lodash": "^4.17.15",
"md5": "2.2.1",
"moment": "2.24.0",
"nprogress": "0.2.0",
"portal-vue": "2.1.6",
"qs": "6.7.0",
"uuid": "7.0.3",
"vue": "2.6.7",
"vue-router": "3.0.2",
"vuex": "3.1.0",
"xlsx": "0.14.1",
"yup": "0.26.10"
},
"devDependencies": {
"#vue/cli-plugin-babel": "3.4.1",
"#vue/cli-plugin-eslint": "3.4.1",
"#vue/cli-service": "3.4.1",
"#vue/eslint-config-prettier": "4.0.1",
"babel-eslint": "10.0.1",
"eslint": "5.14.1",
"eslint-plugin-vue": "5.2.2",
"vue-cli-plugin-element": "1.0.1",
"vue-template-compiler": "2.6.7"
},
"main": ".eslintrc.js",
"author": "Bilal Saeed",
"license": "ISC",
"description": ""
}
I have no experience with configuration of VUE.js app, just read the provided manual for installation of software and whenever I faced any bug during configuration, I googled it. But in this case, I'm not having any error.

After Svelte/Sapper app delopy on Heroku 404 The requested page could not be found

I have a Svelte app deployed to Heroku. This is a legacy code, at first I had 500 error, but after I installed serve the 500 error is gone, but I get the abovementioned 404. I have created another folder on my computer and pulled this very app from Heroku with heroku git:clone -a , ran npm install and it works like a charm locally. I do not get any errors in the console nor in my IDE. I found solutions saying that pushing my build folder can help, but so I did and nothing.
Would someone please pint me to the proper solution, this is my package.json, if necessary I will provide other data.
{
"private": true,
"name": "x",
"description": "y",
"version": "2.0.111",
"license": "MIT",
"scripts": {
"predeploy": "npm version patch && git push && git push --tags",
"deploy": "git push -f heroku master",
"heroku-postbuild": "run-p build",
"dev": "sapper dev",
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "serve -s build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
},
"dependencies": {
"compression": "^1.7.1",
"lodash-es": "^4.17.15",
"polka": "next",
"serve": "^12.0.0",
"sirv": "^0.4.0"
},
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/plugin-transform-runtime": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/runtime": "^7.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^1.12.0",
"rollup-plugin-babel": "^4.0.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-svelte": "^5.0.1",
"rollup-plugin-terser": "^5.1.1",
"sapper": "^0.27.0",
"svelte": "^3.0.0"
},
"repository": {
"type": "git",
"url": "git#github.com:confrontjs/2019.confrontjs.com.git"
}
}
Thanks!

fullfillment dialogflow code cannot connect with realtime database

I have this fullfillment dialogflow code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
...............
app.intent('Control_Devices',(conv, { devices, status }) => {
return admin.database().ref(`/ESP8266/${devices}/value`).set(status)
.then(snapshot => {
conv.ask(`OK, ${devices} ${status}. Do you want more?`);
conv.ask(new Suggestions(intentSuggestions));
});
});
and have an error with return admin.database().ref().set() .then(snapshot =>{});
It cannot connect with my realtime database. Can anyone help me fix this !!!!
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
}
This is my package.json
I edit to this but it isnt work
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^7.0.0",
"firebase-functions": "^2.2.0",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
}

Resources