After firebase deploy in flutter web I get this error:
In this answer person recommends firebase init, but I already have Firebase in the app.
Thanks for any ideas!
I came across this issue with a custom build process and pointing only to my dist folder.
There are three requirements for a successful build:
a firebase.json with functions.source pointing to a directory containing a package.json
The package.json containing a "main":"path-to-index.js" field.
A node engine specified in either the package.json or firebase.json
//firebase.json
{
"functions": {
"source": "./some-dir"
}
}
//some-dir/package.json
{
"main": "lib/index.js",
"engines": {
"node": "16"
}
}
Related
I've set up multiple different indexes on my Firestore development database. Now, I would like to export them into the firestore.indexes.json so that the process of setting up prod environment would be easier. Is there a way to export those indexes using Firebase CLI? The same applies to security rules, although I know that I can copy paste them.
It's possible!
Run from CLI firebase firestore:indexes inside your firebase project folder.
Providing you have indexes already setup and logged into Firebase via the CLI too, you'll get a formatted JSON output for you to copy.
Example:
{
"indexes": [
{
"collectionId": "teslaData",
"fields": [
{
"fieldPath": "Model",
"mode": "ASCENDING"
},
{
"fieldPath": "Price",
"mode": "ASCENDING"
}
]
}
]
}
Exported indexes can be re imported using firebase deploy --only firestore:indexes. Check following doc extract.
https://firebase.google.com/docs/firestore/query-data/indexing
You can also deploy indexes with the Firebase CLI. To get started, run
firebase init firestore in your project directory. During setup, the
Firebase CLI generates a JSON file with the default indexes in the
correct format. Edit the file to add more indexes and deploy it with
the firebase deploy command. If you only want to deploy indexes, add
the --only firestore:indexes flag. If you make edits to the indexes
using the Firebase console, make sure you also update your local
indexes file.
I'm using Firebase CLI 4.2.1 if that helps.
Edit: It's still working as of 9.6.0.
In your Firebase project folder execute this in the terminal:
firebase firestore:indexes > firestore.indexes.json
And it will save a file called firestore.indexes.json with your indexes.
You can then upload that file onto other Firebase projects.
I don't think there is currently an API for getting the Firestore security rules from a project. You can deploy rules through the CLI, which can also be embedded in custom Node scripts, and invoked from CI processes. But as far as I know there is no API to read the rules from a project.
It sounds like a good reason to file a feature request.
This is how my project files are laid out
myProjectFolder
.firebaserc
firebase.json
firestore.indexes.json
functions
Run the commands firebase use myApp-dev then firebase firestore:indexes > firestore.indexes.json to export your current dev project's indexes to a file
myApp-dev and myApp-prod is the "Project ID". To find it in Firebase, click the cog wheel next to "Project Overview" --> Project settings --> General tab (you should see it below)
In file firebase.json make sure it is pointing to the exported firestore.indexes.json for its indexes:
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"firestore": {
"indexes": "firestore.indexes.json"
}
}
Run the commands firebase use myApp-prod and firebase deploy --only firestore:indexes
If the accepted answer isn't working for you (I got a permissions error) for firestore indexes you can go to your firebase console > Cloud firestore > Indexes then open up the network tab in inspector, clear all the requests and refresh the page. Once the page is loaded you can find the JSON formatted response of the indexes (I found mine by searching the word 'indexes' in the search bar of the network tab) in the XHR filter of network requests. It should look something like 'indexes?key=...' you can copy this JSON response.
If you've already initialized firebase in your project with firebase init, you can simply paste it into your project's firestore.indexes.json file.
Then change each name property to a collectionGroup property. eg: 'name': 'projects/[your project name]...' to 'collectionGroup': '[name of collection for this index]'
Run firebase deploy --only firestore:indexes to update any changes made in your text editor back to the firestore indexes tab
for firestore security rules, in a less complicated but similar manner, you can copy and paste the rules shown in the firebase console into the firestore.rules file of your project.
sample firestore.indexes.json file
{
"indexes": [
{
"collectionGroup": "faq",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "searchKeywords",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "answered",
"order": "ASCENDING"
},
{
"fieldPath": "relevanceScore",
"order": "ASCENDING"
},
{
"fieldPath": "__name__",
"order": "ASCENDING"
}
]
}
]
}
The Cloud Firestore Index Definition Reference page shows how.
You can export indexes with the CLI using firebase
firestore:indexes.
I've set up multiple different indexes on my Firestore development database. Now, I would like to export them into the firestore.indexes.json so that the process of setting up prod environment would be easier. Is there a way to export those indexes using Firebase CLI? The same applies to security rules, although I know that I can copy paste them.
It's possible!
Run from CLI firebase firestore:indexes inside your firebase project folder.
Providing you have indexes already setup and logged into Firebase via the CLI too, you'll get a formatted JSON output for you to copy.
Example:
{
"indexes": [
{
"collectionId": "teslaData",
"fields": [
{
"fieldPath": "Model",
"mode": "ASCENDING"
},
{
"fieldPath": "Price",
"mode": "ASCENDING"
}
]
}
]
}
Exported indexes can be re imported using firebase deploy --only firestore:indexes. Check following doc extract.
https://firebase.google.com/docs/firestore/query-data/indexing
You can also deploy indexes with the Firebase CLI. To get started, run
firebase init firestore in your project directory. During setup, the
Firebase CLI generates a JSON file with the default indexes in the
correct format. Edit the file to add more indexes and deploy it with
the firebase deploy command. If you only want to deploy indexes, add
the --only firestore:indexes flag. If you make edits to the indexes
using the Firebase console, make sure you also update your local
indexes file.
I'm using Firebase CLI 4.2.1 if that helps.
Edit: It's still working as of 9.6.0.
In your Firebase project folder execute this in the terminal:
firebase firestore:indexes > firestore.indexes.json
And it will save a file called firestore.indexes.json with your indexes.
You can then upload that file onto other Firebase projects.
I don't think there is currently an API for getting the Firestore security rules from a project. You can deploy rules through the CLI, which can also be embedded in custom Node scripts, and invoked from CI processes. But as far as I know there is no API to read the rules from a project.
It sounds like a good reason to file a feature request.
This is how my project files are laid out
myProjectFolder
.firebaserc
firebase.json
firestore.indexes.json
functions
Run the commands firebase use myApp-dev then firebase firestore:indexes > firestore.indexes.json to export your current dev project's indexes to a file
myApp-dev and myApp-prod is the "Project ID". To find it in Firebase, click the cog wheel next to "Project Overview" --> Project settings --> General tab (you should see it below)
In file firebase.json make sure it is pointing to the exported firestore.indexes.json for its indexes:
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"firestore": {
"indexes": "firestore.indexes.json"
}
}
Run the commands firebase use myApp-prod and firebase deploy --only firestore:indexes
If the accepted answer isn't working for you (I got a permissions error) for firestore indexes you can go to your firebase console > Cloud firestore > Indexes then open up the network tab in inspector, clear all the requests and refresh the page. Once the page is loaded you can find the JSON formatted response of the indexes (I found mine by searching the word 'indexes' in the search bar of the network tab) in the XHR filter of network requests. It should look something like 'indexes?key=...' you can copy this JSON response.
If you've already initialized firebase in your project with firebase init, you can simply paste it into your project's firestore.indexes.json file.
Then change each name property to a collectionGroup property. eg: 'name': 'projects/[your project name]...' to 'collectionGroup': '[name of collection for this index]'
Run firebase deploy --only firestore:indexes to update any changes made in your text editor back to the firestore indexes tab
for firestore security rules, in a less complicated but similar manner, you can copy and paste the rules shown in the firebase console into the firestore.rules file of your project.
sample firestore.indexes.json file
{
"indexes": [
{
"collectionGroup": "faq",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "searchKeywords",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "answered",
"order": "ASCENDING"
},
{
"fieldPath": "relevanceScore",
"order": "ASCENDING"
},
{
"fieldPath": "__name__",
"order": "ASCENDING"
}
]
}
]
}
The Cloud Firestore Index Definition Reference page shows how.
You can export indexes with the CLI using firebase
firestore:indexes.
This drives me crazy - I'm getting the below error during firebase deploy (click the image to enlarge):
package.json
{
"engines": {
"node": "10"
},
"main": "src/index.js",
...
}
The index.js does exist under the src folder.
I tried to change the path in "main" to a fake path and then it fails before deployment which is expected.
However with the "main": "src/index.js" it actually starts to deploy and fails much later during the process as shown on the screenshot above.
What am I missing here?
I'm using firebase-tools v8.12.0
Please, check build steps and your functions configuration in firebase.json.
I've set up multiple different indexes on my Firestore development database. Now, I would like to export them into the firestore.indexes.json so that the process of setting up prod environment would be easier. Is there a way to export those indexes using Firebase CLI? The same applies to security rules, although I know that I can copy paste them.
It's possible!
Run from CLI firebase firestore:indexes inside your firebase project folder.
Providing you have indexes already setup and logged into Firebase via the CLI too, you'll get a formatted JSON output for you to copy.
Example:
{
"indexes": [
{
"collectionId": "teslaData",
"fields": [
{
"fieldPath": "Model",
"mode": "ASCENDING"
},
{
"fieldPath": "Price",
"mode": "ASCENDING"
}
]
}
]
}
Exported indexes can be re imported using firebase deploy --only firestore:indexes. Check following doc extract.
https://firebase.google.com/docs/firestore/query-data/indexing
You can also deploy indexes with the Firebase CLI. To get started, run
firebase init firestore in your project directory. During setup, the
Firebase CLI generates a JSON file with the default indexes in the
correct format. Edit the file to add more indexes and deploy it with
the firebase deploy command. If you only want to deploy indexes, add
the --only firestore:indexes flag. If you make edits to the indexes
using the Firebase console, make sure you also update your local
indexes file.
I'm using Firebase CLI 4.2.1 if that helps.
Edit: It's still working as of 9.6.0.
In your Firebase project folder execute this in the terminal:
firebase firestore:indexes > firestore.indexes.json
And it will save a file called firestore.indexes.json with your indexes.
You can then upload that file onto other Firebase projects.
I don't think there is currently an API for getting the Firestore security rules from a project. You can deploy rules through the CLI, which can also be embedded in custom Node scripts, and invoked from CI processes. But as far as I know there is no API to read the rules from a project.
It sounds like a good reason to file a feature request.
This is how my project files are laid out
myProjectFolder
.firebaserc
firebase.json
firestore.indexes.json
functions
Run the commands firebase use myApp-dev then firebase firestore:indexes > firestore.indexes.json to export your current dev project's indexes to a file
myApp-dev and myApp-prod is the "Project ID". To find it in Firebase, click the cog wheel next to "Project Overview" --> Project settings --> General tab (you should see it below)
In file firebase.json make sure it is pointing to the exported firestore.indexes.json for its indexes:
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
],
"firestore": {
"indexes": "firestore.indexes.json"
}
}
Run the commands firebase use myApp-prod and firebase deploy --only firestore:indexes
If the accepted answer isn't working for you (I got a permissions error) for firestore indexes you can go to your firebase console > Cloud firestore > Indexes then open up the network tab in inspector, clear all the requests and refresh the page. Once the page is loaded you can find the JSON formatted response of the indexes (I found mine by searching the word 'indexes' in the search bar of the network tab) in the XHR filter of network requests. It should look something like 'indexes?key=...' you can copy this JSON response.
If you've already initialized firebase in your project with firebase init, you can simply paste it into your project's firestore.indexes.json file.
Then change each name property to a collectionGroup property. eg: 'name': 'projects/[your project name]...' to 'collectionGroup': '[name of collection for this index]'
Run firebase deploy --only firestore:indexes to update any changes made in your text editor back to the firestore indexes tab
for firestore security rules, in a less complicated but similar manner, you can copy and paste the rules shown in the firebase console into the firestore.rules file of your project.
sample firestore.indexes.json file
{
"indexes": [
{
"collectionGroup": "faq",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "searchKeywords",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "answered",
"order": "ASCENDING"
},
{
"fieldPath": "relevanceScore",
"order": "ASCENDING"
},
{
"fieldPath": "__name__",
"order": "ASCENDING"
}
]
}
]
}
The Cloud Firestore Index Definition Reference page shows how.
You can export indexes with the CLI using firebase
firestore:indexes.
how to deploy to other firebase hosting sites defined within the same project.
I created multiple firebase hosting "sites".
The command
firebase deploy
however always deploys to the first one.
How can I specify that the static files get deployed to another "site" (and domain).
Thanks
You have to add the other sites as deploy targets. If you have a second site named awesome-site-d3426:
$ firebase target:apply hosting awesome-app awesome-site-d3426
You'll likely have to do the same thing for the primary site.
Then tell Firebase what to deploy to which targets in firebase.json:
{
"hosting": [
{
"target": "awesome-site",
"public": "awesome-site/dist"
},
{
...
}
]
}
You can then deploy all the sites at once(firebase deploy) or a specific site:
$ firebase deploy --only hosting:awesome-site
To deploy to another site created in same firebase project.
Update your firebase.json file as folow
{
"hosting": {
"site":"<site-name>",
"public": ...,
"ignore": [
...
],
"rewrites": [
...
]
}
}