Open cyrusonline opened 5 years ago
document.addEventListener('deviceready', function() {
var options = {
"datePrefix": '__DATE:',
"fieldValueDelete": "__DELETE",
"fieldValueServerTimestamp" : "__SERVERTIMESTAMP",
"persist": true
};
if (cordova.platformId === "browser") {
options.config = {
apiKey: "(your api key)",
authDomain: "localhost",
projectId: "(your project id)"
};
}
Firestore.initialise(options).then(function(db) {
// Add a second document with a generated ID.
db.collection("users").add({
first: "Alan",
middle: "Mathison",
last: "Turing",
born: 1912
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
});
});
When I'm trying to replicate this Firestore initialization, I get the following:
Uncaught Error: Cannot instantiate firebase-firestore - be sure to load firebase-app.js first.
at index.esm.js:17501
at index.esm.js:41
I thought it was taken care of in the plugin, so I'm probably doing something wrong?
Please share your project files in order to reproduce your issue.
Which files should I share?
In package.json
cordova-plugin-firestore is listed as dependency and cordova plugin.
in config.xml
cordova-plugin-firestore is listed as plugin.
In order to reproduce your issue, please all files (www, config.xml, package.json at least) on to GitHub. Create a repository, then put them to there please.
What will do are:
$> git clone (repo)
$> cd (repo)
$> npm i
$> cordova prepare
$> cordova run browser/android/ios
You don't need to share actual your project code, but please create a project that reproduce your issue 100% instead. Thank you for your understanding and cooperation.
Thanks for your quick responses! Here is a vanilla repo I just made - it has the same issue: https://github.com/ukuleleplayer/firestore_plugin
Thank you for sharing the project.
The problem is you use older version(1.3.0)
.
https://github.com/ukuleleplayer/firestore_plugin/blob/179e650/config.xml#L26
The latest version is 1.3.2
, which is only available from Github.
The following steps solves this problem.
$> cordova plugin rm cordova-plugin-firestore
$> cordova plugin add https://github.com/ReallySmallSoftware/cordova-plugin-firestore
I don't know why @ReallySmallSoftware does not release the version. Maybe he has some reasons.
You will notice another error.
This error occurs because timestampsInSnapshots
is false
.
I created timestampsInSnapshots
is true
by default, by the author of this plugin (@ReallySmallSoftware ) changes the default settings to keep the backward compatibility.
To prevent this error message, you need to set timestampsInSnapshots
option.
// Initialize Firebase
var options = {
"datePrefix": '__DATE:',
"fieldValueDelete": "__DELETE",
"fieldValueServerTimestamp": "__SERVERTIMESTAMP",
"persist": true,
"timestampsInSnapshots": true, // <-- set true
"config": {}
};
I will be releasing a new version shortly - I am testing the recent changes and prefer to integrate and test with a real world app that uses a lot of the functionality to make sure there are no obvious breaking changes.
Sorry if this takes a little longer than is ideal, but this is only a side project!
An update: My testing has shown a significant number of breaking changes with the latest version that is in github. I am working to correct these and finish support for Geopoint and Timestamp.
Expected Behavior
Actual Behavior
Steps to Reproduce the Problem
Specifications