pg.Pool is not a constructor - node.js

I have a google cloud function using this code and it gives the error TypeError: pg.Pool is not a constructor at exports.postgresDemo I have
{
"dependencies": {
"pg": "^2.0.5"
}
}
as the dependencies. I don't know if the error is in node or cloud functions

Should have been obvious from your dependencies :
"dependencies": {
"pg": "^2.0.5"
}
}
I ran this:
const pg = require('pg')
const pool = new pg.Pool()
console.log(pool)
and got the expected result. Difference is, in my dependencies, I have :"pg": "^7.7.1". The google example you are using also uses a more recent version of pg.
I tried to install your version to double check using npm install pg#2.0.5 but got the error: npm ERR! notarget No matching version found for pg#2.0.5
So upgrade pg and it will work

Related

React Module not found: Error: Default condition should be last one

I'm working on a React project setup using node 16.17.0, Create React App "react-scripts": "^5.0.0" with "react": "^17.0.2"
Everything was working fine until this morning. When I try to npm run start or npm run build, it gives me the below error. The npm install works fine showing no errors.
The errors that I am getting are:
ERROR in ./src/services/auth/firebase/firebase.js 3:0-45
Module not found: Error: Default condition should be last one
ERROR in ./src/services/auth/firebase/firebase.js 4:0-40
Module not found: Error: Default condition should be last one
ERROR in ./src/app/pages/payout/PayoutOpen.js 5:0-39
Module not found: Error: Default condition should be last one
ERROR in ./node_modules/#react-query-firebase/auth/dist/bundle.es.js 3:0-78
Module not found: Error: Default condition should be last one
ERROR in ./node_modules/#react-query-firebase/auth/dist/bundle.es.js 4:0-720
Module not found: Error: Default condition should be last one
This is how my firebase.js file looks like:
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
const firebase = initializeApp({
apiKey: "********",
authDomain: "*******",
projectId: "*********",
storageBucket: "**********",
messagingSenderId: "***************",
appId: "****************",
measurementId: "*************"
});
export const auth = getAuth(firebase);
I tried to remove node_modules folder, remove package-lock.json file, clear npm cache but nothing works. I also tried to install using yarn but it shows the same error.
Fresh issue as per 03 Feb 2023, happens due to firebase v9.17.0.
Fix:
npm un firebase
npm i firebase#9.16.0
Or:
modify package.json, use "firebase": "9.16.0" instead of "firebase": "^9.16.0".
run npm i or yarn.
Related github issue: https://github.com/firebase/firebase-js-sdk/issues/7005

Can't resolve 'fs' in Laravel + Vue Project

please help me with this problem.
i tried to implement 'fs' dependency in vue laravel file.
i installed the dependency using npm i fs
and i add this line to include the library inside my app.vue file
const fs = require('fs');
but when i run the npm run hot, i got this error
ERROR in ./resources/js/vue/app.vue?vue&type=script&lang=js& (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5[0].rules[0].use[0]!./node_modules/vue-loader/lib/index.js??vue-loader-options!./resources/js/vue/app.vue?vue&type=script&lang=js&) 235:15-28 Module not found: Error: Can't resolve 'fs' in 'C:\laragon\www\cms-laravel\resources\js\vue'
i tried to look for the solution and it looks like i need to add these lines to my webpack.mix.js
mix.webpackConfig({ node: { fs: 'empty' }})
So i did, but now got another error like this.
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
configuration.node has an unknown property 'fs'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
and i dont think that i found any solution for this... please help me...
Here's my dependecies in package.json
"dependencies": {
"fs": "0.0.1-security",
"vue": "^2.6.14"
}

How to fix 'Error: FIRESTORE (4.8.0) INTERNAL ASSERTION FAILED: Unknown relation: array-contains'

I get this error message in my browser when I call my web page Error: FIRESTORE (4.8.0) INTERNAL ASSERTION FAILED: Unknown relation: array-contains
This is working on my local machine and started when i change a firestore query to use array-contains
I read about update my Admin SDK to 6.0.0 or later but i think is not working or I'm doing it wrong, I followed this steps from firebase page:
https://firebase.google.com/docs/admin/migrate-admin#admin_java_sdk_600
I have checked my Node.js version and is : v12.4.0
This is an exapmle of code that I implemented
let doc = this.database.collection('Articles')
.where('SerachIndex','array-contains',this.TextParams);
I'm specting make querys using arrar-contains operator but i don't know how to update admin SDK 4.8 to 6.0 or later in my local machine
As you stated you need to update to admin SDK 6.0 or later (now on version 8.6.1).
In your package.json for your nodeJS application change
"dependencies": {
"firebase-admin": "^4.8.0",
}
to
"dependencies": {
"firebase-admin": "^6.0.0",
}
(or "^8.6.1" as that is the latest version)
Then run npm install
You may then need to consult the change logs (such as the link that you posted) to update your current implementation of the adminSDK if anything has been deprecated in that time.

How do I install npm packages on Google Cloud Functions?

I'm trying to create a simple function that:
fetches a JSON file from a public URL
does a little number crunching and spits out an answer.
I figured that Google Cloud Functions would be the perfect fit since I can code in JS and don`t have to worry about server deployment, etc.
I've never really used nodejs/npm so maybe this is the issue, but I tried reading online and they just mention
npm install package-name
I'm not sure where I can do this on the Google Cloud Functions page.
I'm currently using the inline editor and I have the following:
var fetch = require('node-fetch');
exports.test2 = (req, res) => {
fetch("myURLgoes here").then(function(response){
res.status(200).send('Success:'+response);
});
I get the following error:
Error: function crashed.Details:
fetch is not defined
From Google Cloud Platform console, go to your cloud functions.
You should have two files when creating or editing a functions:
- index.js: where you define your functions
- package.json: where you define your dependency.
Your package.json at the start is something like this:
{
"name": "sample-http",
"version": "0.0.1"
}
Add in your package.json all your module that you'd like to install with the command npm install as below:
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"#material-ui/core": "^4.1.1"
}
}
you can find the last version of the package on www.npmjs.com
You can run the npm command from the Google Cloud Shell (which you can access from the Google Cloud Console).

Firebase -Node.js auto complete doesn't show .auth() or it's accompanying methods

I'm running Node version 7.8.0
I have installed the Firebase and Firebase-admin modules into a Server side Node.js app.js file. I want to use these 2 methods:
var myCustomToken = '12345'
firebaseAdmin.auth().createCustomToken(myCustomToken) //firebaseAdmin.auth()
firebase.auth().authenticateWithCustomToken(myCustomToken) // firebase.auth()
The problem is dot .auth() doesn't show up for either module so I can't get to use the 2 methods. There are other methods that are tied to both modules that appear (in pics below) but .auth() isn't one of them.
For e.g.
firebaseAdmin.initializeApp(... //works
firebaseAdmin.credential.cert(... //works
firebase.initializeApp(...) //works
These are the modules I installed in the folder that was initialized with npm:
npm install firebase-admin --save
npm install algoliasearch --save
npm install firebase --save
These are the dependencies inside my package.json file:
"engines": {
"node": "7.8.0"
},
"dependencies": {
"algoliasearch": "^3.22.1",
"firebase": "^3.7.4",
"firebase-admin": "^4.1.4"
}
How can I get .auth() to appear on each module so I can access the 2 methods I need?
Firebase-admin module autocomplete:
Firebase module autocomplete:
Autocomplete results for both modules .auth() doesn't exist:
Have a look at https://firebase.google.com/docs/admin/setup
and https://firebase.google.com/docs/auth/admin/create-custom-tokens#create_custom_tokens_using_the_firebase_admin_sdk
for createCustomToken()
As for the client part, did you try signInWithCustomToken() ?
I filed an issue report at the Firebase-admin github repo and they got back to me and said that even though the .aut() object isn’t showing up in Sublime’s autocomplete it does exist. Since I knew the methods I was looking they said I could just manually put in the code and it would work which in fact it did.
One thing they suggested was that next time I can go into the node_modules folder and I would see that it does exist there:
node_modules/firebase-admin/lib/firebase-namespace.js
this is what is there:
Object.defineProperty(FirebaseNamespace.prototype, "auth", {
/**
* Gets the `Auth` service namespace. The returned namespace can be used to get the
* `Auth` service for the default app or an explicitly specified app.
*/
get: function () {
var _this = this;
var fn = function (app) {
return _this.ensureApp(app).auth();
};
return Object.assign(fn, { Auth: auth_1.Auth });
},
enumerable: true,
configurable: true
});
Basically if your using Sublime and autocomplete isn’t showing what your looking for just manually type it in and look through the node_modules folder to verify it’s there.
Another alternative is to use VSCode or Vim instead of Sublime and the autocomplete should work there.

Resources