I am building a react app.
In my react app I have environment variables which I am acessing using process.env
Something like this
firebase.initializeApp({
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSANGER_ID,
appId: process.env.REACT_APP_ID,
measurementId: process.env.REACT_APP_MEASUREMENT_ID,
});
I want these variables to have value when gatsby is making my production build , I am not sure if this is correct, but I have added them in settings in my travis. Is this correct? Will my react have access to above variables?
Update: They aren't accessible in travis with above approach. so can someone help me in comprehending on how to set react variables in travis?
I aslo want to deploy by static site it to firebase hosting, In the above image, the first name is firebase which contains my firebase token.
How can I access that token in my travis cli?
Update: Here is how my travis.yml looks like
language: node_js
node_js: -"node"
before_script: -"npm install firebase-tools -g"
-"npm install gatsby -g"
-"npm install"
script: -"npm run develop"
after_success: -"firebase deploy --token=${firebase}"
Related
I am developing a RN app in Expo with firebase as backend. So far, the app only uses firebase auth and firestore and for whatever reason, I randomly started getting the error of ReferenceError: Can't find variable: IDBIndex. I adjusted my firebase config to suit the v9 standards instead of using the compat package. I ensured my app was not using Google Analytics. I have also downgraded to firebase#9.1.0 which matches up with the expo documentation and this other similar post.
I have also git reverted into previous versions of the app (with earlier dependencies and code) when it was working but still got back the same error. When this occurred, I entirely reinstalled node and npm because I thought that was the only other possible reason this could be happening but that was to no avail as well (getting the same IDB error). I still think this is a firebase related issue, but I am pretty much all out of ideas as to what it could be.
Here is my firebase config:
import { initializeApp } from 'firebase/app'
import { getAuth, connectAuthEmulator } from "firebase/auth";
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore";
import {
FIREBASE_API_KEY,
FIREBASE_AUTH_DOMAIN,
FIREBASE_PROJECT_ID,
FIREBASE_STORAGE_BUCKET,
FIREBASE_MESSAGING_SENDER_ID,
FIREBASE_APP_ID,
FIREBASE_MEASUREMENT_ID,
} from '#env';
const firebaseConfig = {
apiKey: FIREBASE_API_KEY,
authDomain: FIREBASE_AUTH_DOMAIN,
projectId: FIREBASE_PROJECT_ID,
storageBucket: FIREBASE_STORAGE_BUCKET,
messagingSenderId: FIREBASE_MESSAGING_SENDER_ID,
appId: FIREBASE_APP_ID,
measurementId: FIREBASE_MEASUREMENT_ID,
};
const app = initializeApp(firebaseConfig);
export default app;
export const auth = getAuth(app);
export const firestore = getFirestore(app);
if (process.env.NODE_ENV === "development") {
connectAuthEmulator(auth, "http://localhost:9099");
connectFirestoreEmulator(firestore, "localhost", 8080);
}
Do let me know if you need to see more files or need to know more details.
firebaser here
There was a problem in our JavaScript SDKs, where Firebase Installation Services used a version of IDB that doesn't support ESM outside of browser environments. The issue has been fixed in version 9.6.9 of the JavaScript SDK, so be sure to update to that.
I'm getting the same issue, looks like, it's breaking on "firebase": "^9.6.8", which was released a few days ago. Use "firebase": "9.6.7",
I've been getting the same issue, I've tried all the same things as you to no avail. I symbolicated the logs from firebase test lab and came up with this:
Stacktrace
Generally I have no idea how all of these libraries work together, but are you using typesense with firestore? I wonder if your stack trace calls out the same files, but I can't find any smoking gun here. I'll keep updating this thread if I find something. (I would have commented but I don't have the rep yet)
Update: Looks like my build just fixed itself somehow, even submitting builds from this weekend that would constantly crash. So truly I'm not sure what happened but it may be resolved
I had the same issue, my solution was to downgrade the Firebase version from 9.6.8 to 8.2.3.
Here is a reference that could be helpful.
https://github.com/expo/expo-cli/issues/3066
I had this same issue, and after trying multiple different firebase versions, this is the one that fixed the error for me:
npm install firebase#9.4.1 --save
Here's where I found this: Get Started with Cloud Firestore
The other fixes mentioned in this thread are definitely all valid (I have seen other forum posts suggesting the firebase downgrade but in my case it did not work.)
I thought it could be helpful for me to confirm what fixed the problem in my case. The problem arose from when one of my team members used npm instead of expo (which defaults to yarn) to install a dependency. This caused syncing issues between the yarn.lock and package-lock.json. This alone wouldn't have caused much of an issue because a simple yarn or yarn install <dependency> would have solved the issue. However, this dependency happened to require pre-existing dependencies which were of a different version then the ones "expected" by my version of expo. How this IDBIndex error was triggered is still a mystery to me, but in the end all I had to do was remove all my lock files and node_modules, perform an expo updateand finally do a yarn to reinstall all now-compatible packages.
If anyone stumbling across this answer can give a possible explanation as to why this fixed things, that would be much appreciated.
Here is what worked for me (using yarn):
deleted node_modules
deleted yarn.lock
downgraded to firebase "9.6.7" yarn add firebase#9.6.7
downloaded packages using yarn install
made sure all my imports are from the correct firebase library. I am using expo, and I had imported both firebase and react-native-firebase, which was causing trouble. I deleted react-native-firebase for now until I eject if needed.
Fixed my imports. Now you import firebase like this import firebase from "firebase/compat"
if you use firebase analytics, remove it
firebase version "firebase": "9.6.7"
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
// import { getAnalytics } from "firebase/analytics";
const firebaseConfig = {
apiKey: process.env.FIREBASE_APP_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.FIREBASE_APP_ID,
measurementId: process.env.FIREBASE_MEASUREMENT_ID,
};
export const app = initializeApp(firebaseConfig);
// export const analytics = getAnalytics(app);
export const firestore = getFirestore(app);
Had the same issue, I just downgraded firebase version and it worked.
you can use this code for downgrading:
npm install firebase#9.4.1 --save
This worked for Expo:
https://github.com/firebase/firebase-js-sdk/issues/6253#issuecomment-1123923581
// metro.config.js
const { getDefaultConfig } = require("#expo/metro-config");
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push("cjs");
module.exports = defaultConfig;
I found this project. After I added to index.html file the following Firebase configuration:
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js";
import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js";
import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js";
import { initializeApp } from "https://www.gstatic.com/firebasejs/8.6.1/firebase-storage.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDoO8efzrDVveeXvqqrc39D3XiqfsyoKeU",
authDomain: "diary-app-course-c6663.firebaseapp.com",
projectId: "diary-app-course-c6663",
storageBucket: "diary-app-course-c6663.appspot.com",
messagingSenderId: "1031493909898",
appId: "1:1031493909898:web:3cd71413645447b67c1c73"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
</script>
Next, I did the following steps on command line:
$ dart pub global activate flutterfire_cli
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"$HOME/.pub-cache/bin"
$ vim ~/.bashrc
$ source ~/.bashrc
$ flutterfire configure
$ curl -sL https://firebase.tools | bash
Unfortunately, I got this error:
$ flutterfire configure
i Found 1 Firebase projects. Selecting project diary-app-course.
FirebaseProjectNotFoundException: Firebase project id "diary-app-course" could not be found on this Firebase account.
$ grep -R diary-app-course *
web/index.html: authDomain: "diary-app-course-c6663.firebaseapp.com",
web/index.html: projectId: "diary-app-course-c6663",
web/index.html: storageBucket: "diary-app-course-c6663.appspot.com",
What did I miss?
Follow these steps:
Remove if their any default project exists in .firebaserc file.
Before:
{
"projects": {
"default": "diary-app-course"
}
}
After
{
"projects": {
}
}
Run this command in Firebase CLI:
firebase logout
Log in again:
firebase login
Again run this command in Firebase CLI
flutterfire configure
Hope this works.
flutterfire configure --project=diary-app-course-c6663
You could see your project id on your firebase link
for example : https://console.firebase.google.com/u/0/project/ this is your project id/database/xxxx/data
So, I made some change: If you are trying to logging in one account for registering firebase while creating new project, and at that time but if your android studio account was another one it will be problem.
Make sure to use one gmail account for registering new project and login that entered project
LOG OUT and LOG IN again
Please choose default account and create
When I try to initialize my service account key like so:
const admin = require('firebase-admin');
const serviceAccount = require("./serviceAccountKey.json");
// Initialize the Firebase Storage admin constant
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "<DATABASE-NAME>.appspot.com",
databaseURL: "https://<DATABASE-NAME>.firebaseio.com"
});
I get the following error Error parsing triggers: Cannot find module './serviceAccountKey.json'
My serviceAccountKey.json file is inside my project name folder.
Also my dependencies from Firebase are the following:
"dependencies": {
"firebase": "^6.5.0",
"firebase-admin": "8.4.0",
"firebase-functions": "^3.2.0"
},
My directory structure is the following:
-server
-idea
-bin
-functions
-node_modules
-public
-routes
-views
-.firebaserc
-.gitignore
- app.js
- firebase.json
- master
- package.json
- package-lock.json
- serviceAccountKey.json ===> ***
- server.iml
Why am I getting this error?
Note: I've done some research on this and my file path does conform with the node.js documentation on using the require method.
Put your serverAccountKey.json file in your "functions" folder. The entire contents of that gets packaged up and sent to Cloud Functions (unless you changed that default in firebase.json). Files that are outside that folder will not be available. Right now, it looks like the file is in "server".
With the latest update of firebase cloud functions, I am getting errors while initializing app, as well as database ref.
First Error:
Following should work based on Firebase functions v1.0 documentation and samples ( https://github.com/firebase/friendlychat-web/blob/master/cloud-functions/functions/index.js )
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(); //this fails
I get following error on firebase deploy for above code:
Error: Error occurred while parsing your function triggers.
Error: Failed to parse app options file: Error: ENOENT: no such file or directory, open '[object Object]'
at FirebaseAppError.FirebaseError [as constructor] (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/utils/error.js:119:28)
at FirebaseNamespaceInternals.loadOptionsFromEnvVar (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:214:19)
at FirebaseNamespaceInternals.initializeApp (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:64:28)
at FirebaseNamespace.initializeApp (/Users/ZZZ/dummy/functions/node_modules/firebase-admin/lib/firebase-namespace.js:362:30)
at Object.<anonymous> (/Users/ZZZ/dummy/functions/index.js:5:7)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
This error is resolved if I pass the config file (but it goes against the firebase documentation)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
var config = {
apiKey: "<APIKEY>",
authDomain: "<DOMAIN>",
databaseURL: "<URL>",
projectId: "<PROJECTID>",
storageBucket: "<BUCKET>",
messagingSenderId: "<ID>"
};
admin.initializeApp(config);//this works
Second Error:When I make database ref call as below , it fails and gives error:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
var config = {
apiKey: "<APIKEY>",
authDomain: "<DOMAIN>",
databaseURL: "<URL>",
projectId: "<PROJECTID>",
storageBucket: "<BUCKET>",
messagingSenderId: "<ID>"
};
const app = admin.initializeApp(config);
exports.updateUserProfile = functions.database.ref('/UserProfile/{userid}')
.onCreate((snapshot, context) => {
console.log(snapshot.val());
});
Logs:
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /Users/ZZZ/dummy/functions
> eslint .
✔ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
Error: Unexpected token o in JSON at position 1
You are experiencing this error because of a bug in firebase CLI version 3.18.1.
Try uninstalling the current version and install 3.18.0 and this should solve the error.
npm uninstall -g firebase-tools
npm install -g firebase-tools#3.18.0
UPDATE:
Firebase CLI version 3.18.2 has been released and the issue is now resolved.
I was experiencing this same error. For me the problem appears to have been resolved when I followed these instructions to migrate from a Javascript project to a Typescript project.
It was a bit of a hail mary and might not actually be what fixed it. Still, if you're still stuck it won't hurt to do a quick backup and give it a shot.
If you've updated the NPM modules, then you are now using the Stable release of Cloud functions v1. There are some minor changes that should be done to your existing code. Please follow the guide below
https://firebase.google.com/docs/functions/beta-v1-diff?utm_source=email&utm_medium=email&utm_campaign=cloud_functions_v1.0
Version 1.0.0 of the Firebase SDK for Cloud Functions introduces some
important changes in the API. The primary change, a replacement of
event.data format with data and context parameters, affects all
asynchronous (non-HTTP) functions. The updated SDK can also be used
with firebase-functions-test, a brand new unit testing companion SDK.
See Unit Testing Functions for more information.
I would like to import a json file into my Firebase database. I tried firebase-import as follows:
$ firebase-import --firebase_url https://mytest.firebaseio.com/ --json test.json
but I am getting a "Permission denied" error.
I know that firebase-import has --auth option, which says "Specify an auth token to use (e.g. your Firebase Secret)". How do I get an auth token or my Firebase Secret?
Looks to me like you need to create a service account (see https://firebase.google.com/docs/server/setup) and the provide the service account JSON to firebase-import using the --service_account command-line option.
Create New Project.
Click Add App
Add Firebase to your web app.
this code will show up
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
**apiKey: "<API_KEY>",**
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
};
firebase.initializeApp(config);
</script>
that is you API key then add -a API_KEY
so you will have
firebase-import --firebase_url https://test.firebaseio-demo.com --json test.json --merge -a API_KEY