I am trying to get firebase to work on my React project (using Webpack v3), but I am having some issues.
I added "firebase": "^4.10.1"
to my package.json
and in a firebase.js
file I added this:
import * as firebase from 'firebase';
const config = {
apiKey: "API_KEY",
authDomain: "DOMAIN",
databaseURL: "DATA_URL",
projectId: "ID",
storageBucket: "STORAGE_BUCKET",
messagingSenderId: "SENDER_ID"
};
firebase.initializeApp(config);
firebase.database().ref().set({
message: 'Connection Successful!'
});
On my app.js
I imported that firebase.js
file.
import './firebase/firebase';
If I am not mistaking I am supposed to get the "Connection Successful!" message over in my database, but it's not working.
Instead I get a console error. I looked around online and found a few people with similar errors saying that adding:
node: {
console: true,
fs: 'empty',
child_process: 'empty',
net: 'empty',
tls: 'empty',
dgram: 'empty',
dns: 'empty',
}
to my webpack.config.json
would fix it. I tried it and id didn't really work.
I didn't get those errors any more, but instead I get Uncaught TypeError: util.inherits is not a function
(full error here). I kept looking and found this on the firebase documentation where they use var firebase = require("firebase/app");
instead of import
. I tried it and still didn't work.
I've tried to yarn add util
, but to no avail.
Any idea why this is happening and /or how to fix it? Thanks.